Fill form and click button using selenium web driver - Java HTML

Java examples for HTML:selenium

Description

Fill form and click button using selenium web driver

Demo Code



import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Php2 {

     public static void main(String[] args) throws InterruptedException {
     WebDriver driver = new FirefoxDriver();
     /*  w  ww  . ja  v a2 s .  co  m*/
     driver.get("http://www.your server.net/");
     
     WebElement element = driver.findElement(By.xpath("html/body/div[2]/div/div/div[2]/ul[2]/li[2]/a"));
     element.click();
     
     
    WebElement element1 = driver.findElement(By.xpath("html/body/div[2]/div/div/div[2]/ul[2]/li[2]/ul/li[2]/a"));
     
     element1.click();
     
     driver.findElement(By.name("firstname")).sendKeys("george");
     
     driver.findElement(By.name("lastname")).sendKeys("benson");
     
     driver.findElement(By.xpath(".//*[@id='headersignupform']/div[5]/input")).sendKeys("4564512121");
     
     int x=1;
     {      
          driver.findElement(By.xpath(".//*[@id='headersignupform']/div[6]/input")).sendKeys("abc"+x+"@gmail.com");
     }
     
     driver.findElement(By.xpath(".//*[@id='headersignupform']/div[7]/input")).sendKeys("abc");
     //enter password
     driver.findElement(By.xpath(".//*[@id='headersignupform']/div[8]/input")).sendKeys("abc");
     // confirm pass word
     driver.findElement(By.xpath(".//*[@id='headersignupform']/div[9]/button")).click();
     
     // sighn up 
     
     driver.findElement(By.xpath("html/body/div[2]/div/div/div[2]/ul[2]/li[2]/ul/li[2]/a")).click();
     
     WebElement element3 = driver.findElement(By.xpath("My Account "));
     element3.click();

     WebElement element4 = driver.findElement(By.xpath("My Account "));
     element4.click();
     Thread.sleep(5000);
     
     driver.close();


     }

}

Related Tutorials