根据我看到的每个答案和文档,下面的内容应该等待xpath path上的元素
delay = some amount of time way longer than I know is neededdriver = webdriver.Firefox()
driver.get(url)
wait = WebDriverWait(driver, delay, ignored_exceptions=NoSuchElementException)
wait.until(EC.presence_of_element_located(driver.find_element_by_xpath(path)))但是无论我做什么,它总是在获得url后立即抛出一个NoSuchElementException。在任何人将其标记为复制或调用我之前,我知道this的答案,虽然我正在寻找的元素是某种包装,但我在尝试上面的包装时遇到了同样的问题(如果我只提供一个普通的sleep调用,而不是Expected Condition,这让我觉得我不需要手动进入包装器)。有一个函数来等待一个元素被加载,直到元素被加载,这又有什么意义呢?如果能帮助解决这个问题,我们将不胜感激。
发布于 2016-10-30 21:07:54
我在类似的情况下使用这个java代码:
private Wait<WebDriver> staleWait = new FluentWait<>(getDriver())
.withTimeout(WAIT_INTERVAL, TimeUnit.SECONDS)
.pollingEvery(POLLING_INTERVAL, TimeUnit.MILLISECONDS)
.ignoring(NoSuchElementException.class)
.ignoring(StaleElementReferenceException.class);
protected WebElement visibilityOf(WebElement webElement) {
staleWait.until((ExpectedCondition<Boolean>) webDriver -> {
try {
return element(webElement).isDisplayed();
} catch (StaleElementReferenceException e) {
return false;
} catch (NoSuchElementException ne) {
return false;
}
});
return element(webElement);
}https://stackoverflow.com/questions/40333067
复制相似问题