简体   繁体   English

Selenium Webdriver和Eclipse Java登录GMAIL的测试用例

[英]Test case for Selenium Webdriver and Eclipse java to login GMAIL

i need to verify user login in gmail using selenium in Eclipse. 我需要在Eclipse中使用硒验证gmail中的用户登录。 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. 1打开谷歌网站,搜索gmail,单击适当的结果,转到https://mail.google.com网站,输入用户名和密码,单击登录,验证用户名。 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");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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