如何减少Selenium中NoSuchElementException的等待时间? [英] How to decrease the wait time for NoSuchElementException in Selenium?

查看:227
本文介绍了如何减少Selenium中NoSuchElementException的等待时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某些情况下,我知道元素将不会显示.但它的等待时间约为30秒.

In some cases, i know element will not be displayed. but its waiting ~30 Secs.

如何减少硒中NoSuchElementException的等待时间?

How to decrease wait time for NoSuchElementException in selenium?

示例代码:

String name;
        try {    
            name = driver.findElement(By.xpath("XPath")).getText();
        } catch (NoSuchElementException e) {
            name = "Name not displayed";
        }

推荐答案

我认为您正在为驾驶员设置隐式等待时间:

I think you're looking for setting the implitic wait time for your driver:

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

对于可以使用的简单情况,对于更高级的自动化,我将其更改为显式等待(使用WebDriverWait).

For simple cases thats ok to use, for more advanced automation, I'd change it to an explicit wait (using WebDriverWait).

更多等待: http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp

这篇关于如何减少Selenium中NoSuchElementException的等待时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆