Limiting the timeout period for Selenium FindElement()

白昼怎懂夜的黑 提交于 2019-12-10 20:52:14

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/43247670/limiting-the-timeout-period-for-selenium-findelement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!