限制Selenium FindElement()的超时时间 [英] Limiting the timeout period for Selenium FindElement()

查看:639
本文介绍了限制Selenium FindElement()的超时时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何限制/减少FindElement的超时时间?我正在抓取一个网站.对于出现在成千上万页中的表,我可以有一个元素说明没有信息,也可以有一个表. 我搜索这些元素之一,而当缺少时,我搜索其他元素.问题是当其中一个不存在时,FindElement超时会花费很长时间.这段时间可以缩短吗?可以为每个元素定义超时期限吗?我发现有关等待的所有内容都是为了延长超时时间. 如果有帮助,我正在.NET环境中工作.

How can I limit/reduce the timeout period for FindElement? I am scraping a website. For a table which appears in thousands of pages, I can have either an element stating there is no information, or the table. I search for one of theses elements and when missing, I search for the other. The problem is that when one of them does not exist, it takes a long time until the FindElement times out. Can this period be shortened? Can the timeout period be defined per element? All I found about waits are to prolong the timeout period... I'm working in a .NET environment, if that helps.

推荐答案

FindElement中的延迟是由隐式等待"设置引起的.您可以将其临时设置为其他值

The delay in FindElement is caused by the Implicit Wait settings. You can set it temporary to different value

driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(0)); // setting to 0 will check one time only when using FindElement

// look for the elements

driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(original settings));

这篇关于限制Selenium FindElement()的超时时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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