首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >直到/WebDriverWait抛出NoSuchElementException

直到/WebDriverWait抛出NoSuchElementException
EN

Stack Overflow用户
提问于 2016-10-30 20:04:54
回答 1查看 495关注 0票数 0

根据我看到的每个答案和文档,下面的内容应该等待xpath path上的元素

代码语言:javascript
复制
delay = some amount of time way longer than I know is needed
代码语言:javascript
复制
driver = 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,这让我觉得我不需要手动进入包装器)。有一个函数来等待一个元素被加载,直到元素被加载,这又有什么意义呢?如果能帮助解决这个问题,我们将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2016-10-30 21:07:54

我在类似的情况下使用这个java代码:

代码语言:javascript
复制
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);
}
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40333067

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档