为什么我无法点击下一步按钮并忘记密码链接?

时间:2018-01-29 07:23:16

标签: selenium selenium-webdriver

enter image description here在下面的代码中,我尝试单击忘记密码链接的最后一行无效。我无法点击忘记密码链接。

package testpackage;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class testclass {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver","D:/chromedriver.exe");//Better place this in a desktop
WebDriver driver = new ChromeDriver();
driver.get("https://www.gmail.com");
//System.out.println(driver.getCurrentUrl());
driver.findElement(By.name("identifier")).sendKeys("j.jagadeesh.1989");

driver.findElement(By.xpath("//*[@id='identifierNext']/content/span")).click();
driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
driver.findElement(By.name("password")).sendKeys("password");
driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
driver.findElement(By.id("forgotPassword")).click();

}
}

1 个答案:

答案 0 :(得分:0)

driver.findElement(By.xpath(".//*[@id='view_container']/form/div[2]/div/div[1]/button")).click();

试试这个。 它将打开忘记密码页面。

只需将忘记密码ID替换为给定ID即可。

我试过这个并且有效。