Selenium WebDriver (2.25) Timeout Not Working Selenium WebDriver (2.25) Timeout Not Working selenium selenium

Selenium WebDriver (2.25) Timeout Not Working


If you are using Firefox 17 and Selenium 2.26.0 then you are hitting defect #4814: http://code.google.com/p/selenium/issues/detail?id=4814


Based on answers found here

1

I would recommend using WebDriverWait with ExpectedConditons.

//scroll down with Javascript firstWebDriverWait wait = new WebDriverWait(driver, 30);WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("selector")));//interact with your elementelement.click()

Take a look at the guidance provided by Selenium Official page:http://seleniumhq.org/docs/04_webdriver_advanced.html

2

try using fluent wait in particular. The main feature is:

An implementation of the Wait interface that may have its timeout and polling interval configured on the fly.Each FluentWait instance defines the maximum amount of time to wait for a condition, as well as the frequency with which to check the condition. Furthermore, the user may configure the wait to ignore specific types of exceptions whilst waiting, such as NoSuchElementExceptions when searching for an element on the page.

public WebElement fluentWait(final By locator){        Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)                .withTimeout(30, TimeUnit.SECONDS)                .pollingEvery(5, TimeUnit.SECONDS)                .ignoring(NoSuchElementException.class);        WebElement foo = wait.until(new Function<WebDriver, WebElement>() {            public WebElement apply(WebDriver driver) {                        return driver.findElement(locator);                }                });                           return  foo;              }     ;

The method described returns you web element you can operate with.So the approach be the following:1) you need to find the selectors of elements you expect to be rendered after scrollinge.g.

String cssSelector = "blablabla"

2) scroll down with js3)

WebElement neededElement  = fluentWait(cssSelector);neededElement.click();//neededElement.getText().trim();

you can get more info about fluent wait here

UPDATE


from selenium import webdriverimport unittest, time, reclass Sdsdsd(unittest.TestCase):    def setUp(self):        self.driver = webdriver.Firefox()        self.driver.implicitly_wait(30)        self.base_url = "https://www.google.com/"        self.verificationErrors = []    def test_sdsdsd(self):        driver = self.driver        driver.get ("http://www.google.com")        try:             driver.find_element_by_id("id_not_found")# I am only searching for the element not assigning it to anything.        except:            raise    def is_element_present(self, how, what):        try: self.driver.find_element(by=how, value=what)        except NoSuchElementException, e: return False        return True    def tearDown(self):        self.driver.quit()        self.assertEqual([], self.verificationErrors)if __name__ == "__main__":    unittest.main()

and I get this exception, which is desired

E======================================================================ERROR: test_sdsdsd (__main__.Sdsdsd)----------------------------------------------------------------------Traceback (most recent call last):  File "sdsdsd.py", line 19, in test_sdsdsd    driver.find_element_by_id("id_not_found")  File "/Library/Python/2.6/site-packages/selenium-2.2.0-py2.6.egg/selenium/webdriver/remote/webdriver.py", line 172, in find_element_by_id    return self.find_element(by=By.ID, value=id_)  File "/Library/Python/2.6/site-packages/selenium-2.2.0-py2.6.egg/selenium/webdriver/remote/webdriver.py", line 525, in find_element    {'using': by, 'value': value})['value']  File "/Library/Python/2.6/site-packages/selenium-2.2.0-py2.6.egg/selenium/webdriver/remote/webdriver.py", line 144, in execute    self.error_handler.check_response(response)  File "/Library/Python/2.6/site-packages/selenium-2.2.0-py2.6.egg/selenium/webdriver/remote/errorhandler.py", line 110, in check_response    raise exception_class(message, screen, stacktrace)NoSuchElementException: Message: u'Unable to locate element: {"method":"id","selector":"id_not_found"}' ; Stacktrace: Method WebDriverError threw an error in file:///private/var/folders/TA/TAS7MYfcEuG3lBNHwhrjRU+++TI/-Tmp-/tmpEf_lrD/extensions/fxdriver@googlecode.com/resource/modules/utils.js ----------------------------------------------------------------------Ran 1 test in 33.818sFAILED (errors=1)

Also note that it failed after 33 seconds, which means it waited for 30 seconds before erroring out.

When i change the implicit wait to self.driver.implicitly_wait(15)

I get this error

E======================================================================ERROR: test_sdsdsd (__main__.Sdsdsd)----------------------------------------------------------------------Traceback (most recent call last):  File "sdsdsd.py", line 19, in test_sdsdsd    driver.find_element_by_id("id_not_found")  File "/Library/Python/2.6/site-packages/selenium-2.2.0-py2.6.egg/selenium/webdriver/remote/webdriver.py", line 172, in find_element_by_id    return self.find_element(by=By.ID, value=id_)  File "/Library/Python/2.6/site-packages/selenium-2.2.0-py2.6.egg/selenium/webdriver/remote/webdriver.py", line 525, in find_element    {'using': by, 'value': value})['value']  File "/Library/Python/2.6/site-packages/selenium-2.2.0-py2.6.egg/selenium/webdriver/remote/webdriver.py", line 144, in execute    self.error_handler.check_response(response)  File "/Library/Python/2.6/site-packages/selenium-2.2.0-py2.6.egg/selenium/webdriver/remote/errorhandler.py", line 110, in check_response    raise exception_class(message, screen, stacktrace)NoSuchElementException: Message: u'Unable to locate element: {"method":"id","selector":"id_not_found"}' ; Stacktrace: Method WebDriverError threw an error in file:///private/var/folders/TA/TAS7MYfcEuG3lBNHwhrjRU+++TI/-Tmp-/tmpXSbCY0/extensions/fxdriver@googlecode.com/resource/modules/utils.js ----------------------------------------------------------------------Ran 1 test in 18.843sFAILED (errors=1)