简体   繁体   中英

Test case for Selenium Webdriver and Eclipse java to login GMAIL

i need to verify user login in gmail using selenium in Eclipse. Following steps are need to complete. 1 open google website,search gmail, click appropriate results, go to https://mail.google.com website, Enter username and pw, Click sign in,verify username. code seems like this but i couldn't automate the password it stops when enter the e-mail

 'package gmailtest;
 import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class firstgmail {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    System.setProperty( 
   "webdriver.gecko.driver","C:\\Desktop\\geckodriver-
    v0.16.1-win64\\geckodriver.exe");
    FirefoxDriver driver=new FirefoxDriver();
    driver.navigate().to("http://www.google.com.");

    WebDriverWait wait =new WebDriverWait(driver,10);
    String caseOfInputField = "input[name='q']";
    WebElement 

   inputFieldQ=wait.until(ExpectedConditions.elementToBeClickable
   (By.cssSelector(caseOfInputField)));
    inputFieldQ.sendKeys("GMAIL");
    //String caseOfSearchButton="button[name='btnG']";
    //WebElement searchButton 

   =wait.until(ExpectedConditions.elementToBeClickable(By.
    cssSelector(caseOfSearchButton)));
    //searchButton.click();

    driver.get("https://www.gmail.com/");
    driver.manage().window().maximize();
    driver.findElement(By.xpath(".//*[@id='identifierId']")).sendKeys("i@gmail.com");
    //driver.findElement(By.id("Email")).sendKeys("t@gmail.com");
    driver.findElement(By.xpath(".//*[@id='identifierNext']/content")).click();
    //driver.findElement(By.cssSelector("#next"));

    driver.findElement(By.xpath(".//*[@id='password']/div[1]/div/div[1]/input")).sendKeys("s@123");;


    //driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.findElement(By.id("signIn")).click();


    //driver.get("http://www.google.com.");
    //driver.findElement(By.xpath(""));




     //driver.quit();

}

}

Try the below code starting from your password filling code

  driver.findElement(By.xpath("//*[@name='password']")).click();
  Thread.sleep(1000);
  driver.findElement(By.xpath("//*[@name='password']")).clear();
  driver.findElement(By.xpath("//*[@name='password']")).sendkeys("yourpassword");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM