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 method in Selenium is a command which helps you identify a web element. There are multiple ways that findElement provides to uniquely identify a web element within the web page using web locators in Selenium like ID, Name, Class Name, Link Text, Partial Link Text, Tag, which we will see later in the blog.
1. implicitlyWait() This timeout is used to specify the amount of time the driver should wait while searching for an element if it is not immediately present.
The default value of timeout is 0. This method is generally used for JavaScript commands in Selenium. If we omit setting time for the script, the executeAsyncScript method can encounter failure due to the more time consumed by the JavaScript to complete execution.
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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With