Trying to verify after few GUI operations some button does not exist (expected not to be present). I am using find_element_by_xpath() but its very slow. Any solution of timeout?
We can also verify if an element is present in the page, with the help of find_elements() method. This method returns a list of matching elements. We can get the size of the list with the len method. If the len is greater than 0, we can confirm that the element exists on the page.
Implicit Waits. An implicit wait tells WebDriver to poll the DOM for a certain amount of time when trying to find any element (or elements) not immediately available. The default setting is 0 (zero). Once set, the implicit wait is set for the life of the WebDriver object.
The Selenium WebDriver scripts are very slow because they run through the browser. There are multiple things that can improve the Selenium WebDriver scripts' speed: use fast selectors. use fewer locators.
Actually WebDriver's find_element method will wait for implicit time for the element if the specified element is not found.
There is no predefined method in WebDriver like isElementPresent() to check. You should write your own logic for that.
Logic
public boolean isElementPresent()
{
try
{
set_the_implicit time to zero
find_element_by_xpath()
set_the_implicit time to your default time (say 30 sec)
return true;
}
catch(Exception e)
{
return false;
}
}
See : http://goo.gl/6PLBw
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