我需要使用Eclipse中的Selenium在Gmail中验证用户登录。需要完成以下步骤。1打开Google网站,搜索Gmail,单击适当的结果,访问https://mail.google.com网站,输入用户名和PW,单击登录,验证用户名。代码似乎是这样,但我无法自动化它在输入电子邮件时停止的密码
'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();
}
}
尝试以下从密码填充代码开始的代码
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");