ExpectedConditions.elementToBeClickable
如果condition为true则返回元素,这意味着如果元素出现在页面上并且是可单击的,则返回元素,无需再次查找此元素,只需省略最后一行,如下所示:-
//Click on Create Account btn:driver.findElement(By.id("createAccount")).click();//Wait till "Cancel" button is showing up. At cases, it may take some time.WebElement el = myWaitVar.until(ExpectedConditions.elementToBeClickable(By.id("cancelRegister")));el.click();Edited1 :-如果由于其他元素而无法单击,则可以
JavascriptExecutor单击以执行单击,如下所示:
//Click on Create Account btn:driver.findElement(By.id("createAccount")).click();//Wait till "Cancel" button is showing up. At cases, it may take some time.WebElement el = myWaitVar.until(ExpectedConditions.elementToBeClickable(By.id("cancelRegister")));((JavascriptExecutor)driver).executescript("arguments[0].click()", el);Edited2
:-从提供的异常看来,进度栏仍覆盖在
cancelRegister按钮上。因此最好的方法是先等待进度条的隐身性,然后等待
cancelRegister按钮的可见性,如下所示:
//Click on Create Account btn:driver.findElement(By.id("createAccount")).click();//Now wait for invisibility of progress bar first myWaitVar.until(ExpectedConditions.invisibilityOfElementLocated(By.id("page_loader")));//Now wait till "Cancel" button is showing up. At cases, it may take some time.WebElement el = myWaitVar.until(ExpectedConditions.elementToBeClickable(By.id("cancelRegister")));el.click();希望它能工作… :)



