Login form using selenium WebDriver - Java HTML

Java examples for HTML:selenium

Description

Login form using selenium WebDriver

Demo Code



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

public class Mercurywebtours2 {

     public static void main(String[] args) {
          WebDriver driver = new FirefoxDriver();
          driver.get("http://newtours.demoaut.com/");
         System.out.println(driver.getTitle());
     //click on register link
          driver.findElement(By.linkText("REGISTER")).click();
     //enter first name
          driver.findElement(By.name("firstName")).sendKeys("TARIKU");
     //enter last name
          driver.findElement(By.name("lastName")).sendKeys("GELAN");
     //enter phone
          driver.findElement(By.name("phone")).sendKeys("123456789");     
     //enter email
          driver.findElement(By.id("userName")).sendKeys("aa@gmail.com");
     //enter Address
          driver.findElement(By.name("address1")).sendKeys("12007 swallow falls ct");
     //enter city
          driver.findElement(By.name("city")).sendKeys("main");          
     //enter state province
          driver.findElement(By.name("state")).sendKeys("maryland");
     //enter postal code
          driver.findElement(By.name("postalCode")).sendKeys("1234");
    //Country/*from   w  ww. j a v  a 2 s  .c  o m*/
          driver.findElement(By.name("country")).sendKeys("united states");
     //enter Username
          driver.findElement(By.id("email")).sendKeys("YourServerName@gmail.com");
     //enter password
          driver.findElement(By.name("password")).sendKeys("vv@gmail.com");
     //confirm  password
         driver.findElement(By.name("confirmPassword")).sendKeys("aa@gmail.com");
     //click on submit link
        driver.findElement(By.name("register")).click();
        driver.getPageSource().contains("Thank you for registering");
     // close the browser
        driver.close();
        
        
     }

}

Related Tutorials