Java 等待。直到不';无法在SeleniumWebDriver中工作
我尝试了以下代码:Java 等待。直到不';无法在SeleniumWebDriver中工作,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,我尝试了以下代码: By by7 = By.xpath(".//*[@id='i2']/div[2]/div[1]"); WebDriverWait wait7 = new WebDriverWait(driver, 10); WebElement elem7 = wait7.until(ExpectedConditions.elementToBeClickable(by7)); driver.findElement(By.xpath(".//*[@id='i2']/div[2]/div[1]"
By by7 = By.xpath(".//*[@id='i2']/div[2]/div[1]");
WebDriverWait wait7 = new WebDriverWait(driver, 10);
WebElement elem7 = wait7.until(ExpectedConditions.elementToBeClickable(by7));
driver.findElement(By.xpath(".//*[@id='i2']/div[2]/div[1]")).click();
但是,当我执行此代码时,我将执行ElementNotVisibleException
命令持续时间或超时:11毫秒
如何传递此异常?等待元素可单击与等待元素可见无关。您可能需要确保您拥有正确的元素,并且它应该/将变得可见。您可以更改
wait.until()
以等待元素变为可见
wait.until(ExpectedConditions.visibilityOfElementLocated(by7))
仅供参考。。。在上一条语句中,您可以使用从wait.until()
返回的元素并单击它。执行此操作:elem7.单击()代码>我不知道这是否能解决您的问题,我注意到这只是一种效率
所以更新后的代码是
By by7 = By.xpath(".//*[@id='i2']/div[2]/div[1]");
WebDriverWait wait7 = new WebDriverWait(driver, 10);
WebElement elem7 = wait7.until(ExpectedConditions.visibilityOfElementLocated(by7));
elem7.click();
确保您不使用ajax。如果有ajax(jQuary),那么你必须等待它。哦,我不知道这是ajax代码。在java中,我可以做什么来等待可见元素?