用于gmail的passwordNext按钮单击并不总是有效。明确的等待似乎也没有帮助。
public void funcLogin() {
driver.findElement(LoginMail).sendKeys(prop.getProperty("email"));
driver.findElement(LoginMail).sendKeys(Keys.RETURN);
driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
driver.findElement(PwdMail).sendKeys(prop.getProperty("passwd"));
driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
driver.findElement(By.id("passwordNext")).click();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
}
错误:
org.openqa.selenium.WebDriverException: unknown error: Element <div role="button" id="passwordNext" class="O0WRkf zZhnYe e3Duub C0oVfc nDKKZc DL0QTb" jscontroller="VXdfxd" jsaction="click:cOuCgd; mousedown:UX7yZ; mouseup:lbsD7e; mouseenter:tfO1Yc; mouseleave:JywGue;touchstart:p6p2H; touchmove:FwuNnf; touchend:yfqBxc(preventMouseEvents=true|preventDefault=true); touchcancel:JMtRjd;focus:AHmuwe; blur:O22p3e; contextmenu:mg9Pef;" jsshadow="" jsname="Njthtb" aria-disabled="false" tabindex="0">...</div> is not clickable at point (787, 340). Other element would receive the click: <div class="ANuIbb IdAqtf" jsname="k4HEge" tabindex="0"></div>
答案 0 :(得分:1)
您必须正确使用显式等待才能使用该功能:
以下是 Gmail 登录的代码,该代码正常运行:
代码
public class QQ_TT {
static WebDriver driver;
static WebDriverWait wait;
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "D:\\Automation\\chromedriver.exe");
driver = new ChromeDriver();
wait = new WebDriverWait(driver,50);
driver.manage().window().maximize();
driver.get("https://www.gmail.com");
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("headingText"))));
driver.findElement(By.id("identifierId")).sendKeys("QQ_TT@gmail.com");
driver.findElement(By.xpath("//span[text()='Next']")).click();
wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("headingText"))));
driver.findElement(By.name("password")).sendKeys("qq_tt@stackoverflow");
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[text()='Next']")));
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[text()='Next']")));
driver.findElement(By.xpath("//span[text()='Next']")).click();
}
}
如果您对此有任何疑虑,请与我们联系。