简体   繁体   中英

Wait.until doesn't work in Selenium WebDriver

I tried this code:

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();

But when i execute this code i'm taking ElementNotVisibleException

Command duration or timeout: 11 milisecond

How can i pass this exception?

Waiting for an element to be clickable is independent of waiting for it to be visible. You might need to make sure you have the right element and that it should be/will become visible. You can vary your wait.until() to wait for the element to become visible.

wait.until(ExpectedConditions.visibilityOfElementLocated(by7))

Just an FYI... your last statement, you can use the element that is returned from the wait.until() and click it. Do this: elem7.click(); I don't know if that will solve your problem, just an efficiency that I noticed.

So the updated code would be

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM