此代码对我有用,请选中复选框,请查看是否对您有帮助
public class webdriver_firefox
{
public static void main(String[] args) throws InterruptedException
{
WebDriver driver = new FirefoxDriver();
driver.get("http://www.gmail.com");
System.out.println(driver.getTitle());
driver.findElement(By.id("Email")).sendKeys("abc@gmail.com");
try{Thread.sleep(4000);}catch(Exception e) {}
driver.findElement(By.id("Passwd")).sendKeys("123654");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.xpath("/html/body/div/div[2]/div/div/form/label")).click(); // this line select the check box please check this
synchronized (driver)
{
driver.wait(2000);
}
//driver.wait(1000, 1 );
driver.findElement(By.id("signIn")).click();