Selenium Webdriver和Eclipse java的测试用例,用于登录GMAIL

时间:2017-05-06 02:16:39

标签: java eclipse selenium

我需要在Eclipse中使用selenium验证用户在gmail中的登录。 以下步骤需要完成。 1.打开谷歌网站,搜索Gmail,点击相应的结果,转到https://mail.google.com网站,输入用户名和密码,点击登录,验证用户名。代码看起来像这样,但我无法自动输入电子邮件时停止的密码

 '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();

}

}

1 个答案:

答案 0 :(得分:0)

从密码填写代码

开始,尝试以下代码
  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");