Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium WebDriver (2.25) Timeout Not Working

I think I've read all the Selenium timeout questions on Stack Overflow, yet neither implicit nor explicit timeout works in my Selenium webdriver 2.25 (Python 2.7 binding) and both "no_timeout_here =" lines would hang forever --

browser = webdriver.Firefox()
browser.implicitly_wait(6)               
browser.set_page_load_timeout(30)        
browser.get("http://www.google.com")
try:
    #no_timeout_here = browser.find_element_by_id("id_not_found")
    no_timeout_here = WebDriverWait(browser, 5).until(lambda browser:
            browser.find_element_by_id("id_not_found"))
except:
    raise

All pointers will be greatly appreciated!

Update Oct. 16th

Thanks to seleniumnewbie for your comprehensive answer, however, your unittest code still hangs on my Ubuntu 11.04 (64-bit) under Python 2.7 --

(2012/10/17 11:51:58)$ time ./timeout.py 
^CTraceback (most recent call last):
...
KeyboardInterrupt

real    2m26.572s
user    0m0.368s
sys 0m0.232s

(2012/10/17 11:54:26)$ python -V
Python 2.7.2+

(2012/10/17 11:57:04)$ uname -a
Linux 3.0.0-26-generic #43-Ubuntu SMP Tue Sep 25 17:19:22 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

(2012/10/17 11:57:10)$ ls selenium-server-standalone-2.25.0.jar

May I know your OS/Python version?

like image 470
Jerry Avatar asked Oct 14 '12 06:10

Jerry


People also ask

How do I fix Selenium timeout exception?

Solution. You can manually increase the wait time by hit-and-trial. If the problem persists for a longer period of time, there may be some other issue and you should continue onto the next solution. You can explicitly add wait by using JavaScript Executor.

What is the default timeout of Selenium WebDriver?

Defaults to 30 seconds (or 30,000 ms). When the object is used as input for the Set Timeouts command or as part of the timeouts capability when creating a new session, all fields are optional.

How does Selenium handle connection timeout?

You should try to increase the timeout to ensure that the objects are available to selenium to work. If you want to handle the error, better include this code in @BeforeTest or @BeforeSuite annotation which ensure the entire test suite will not run if this fails.

How do I make Selenium wait for some time?

Implicit Wait directs the Selenium WebDriver to wait for a certain measure of time before throwing an exception. Once this time is set, WebDriver will wait for the element before the exception occurs. Once the command is in place, Implicit Wait stays in place for the entire duration for which the browser is open.


1 Answers

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

like image 151
medwards Avatar answered Oct 17 '22 04:10

medwards