Showing posts with label Drag and Drop handling with Selenium. Show all posts
Showing posts with label Drag and Drop handling with Selenium. Show all posts

Run a Bat File with Java Program


Sample JAVA Code:

public class RunBat {

public static void main(String[] args) throws IOException, InterruptedException{

Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("cmd /c F:\\bb.bat");
process.waitFor();
}
}

How to register in Facebook?


Below is the code to make an account on Facebook using Selenium Wedriver:

public class FacebookRegistration {

public static void main(String[]args)
{
WebDriver driver = new FirefoxDriver();
driver.get("https://www.facebook.com/");
driver.manage().window().maximize();
driver.findElement(By.xpath("//*[@value='First Name']")).sendKeys("raj");
driver.findElement(By.xpath("//*[@value='Last Name']")).sendKeys("raja");
driver.findElement(By.xpath("//*[@value='Your email address']")).sendKeys("raja@mail.com");
driver.findElement(By.xpath("//*[@value='Re-enter email address']")).sendKeys("raja@mail.com");
driver.findElement(By.xpath("//*[@value='New Password']")).sendKeys("A123a!");
new Select(driver.findElement(By.xpath("//*[@name='birthday_day']"))).selectByValue("1");
new Select(driver.findElement(By.xpath("//*[@id='month']"))).selectByValue("2");
new Select(driver.findElement(By.xpath("//*[@id='year']"))).selectByValue("1987");
driver.findElement(By.xpath("//*[@id='u_0_g']/span[1]/label")).click();
driver.findElement(By.xpath("//*[@id='u_0_i']")).click();
}
}

Automate Drag and Drop Functionality using Selenium 2.0

 

// How to automate Drag and Drop Functionality using Selenium

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class DragNDrop {

 public static void main(String[] args) throws InterruptedException {
  
  WebDriver driver = new FirefoxDriver();
  String URL = "http://www.dhtmlx.com/docs/products/dhtmlxTree/samples/05_drag_n_drop/06_pro_drag_frame.html";
  driver.get(URL);
  driver.manage().window().maximize();
  driver.manage().timeouts().implicitlyWait(10000, TimeUnit.MILLISECONDS);
  WebElement from = driver.findElement(By.xpath("//*[@id='treeboxbox_tree']/div/table/tbody/tr[2]/td[2]/table/tbody/tr[4]/td[2]/table/tbody/tr[2]/td[2]/table/tbody/tr/td[4]/span"));
  
  WebElement to = driver.findElement(By.xpath("//*[@id='treeboxbox_tree']/div/table/tbody/tr[2]/td[2]/table/tbody/tr[6]/td[2]/table/tbody/tr[1]/td[4]/span"));
  
  Actions action = new Actions(driver);
  action.dragAndDrop(from, to).perform();
  Thread.sleep(10000);
  driver.close();
  
 }
 
}