John Slathon
John Slathon

Reputation: 363

Webdriver Ignores Wait - Firefox, Python

After recently changing my OS to Debian Wheezy(KDE) my webdriver, behaves odd. (Coded in python 2.7 for firefox, all modules are up to date.)

It completely ignores wait commands, such as implicitly_wait(). This is highly problematic if a wait is critically needed to access loading web elements.

A dirty workaround is to use time.sleep(), which is functional but certainly not how webdriver is intended to be used.

The following code exemplifies my problem:

from selenium import webdriver
import time

driver = webdriver.Firefox()

driver.get('http://www.google.com')

tc = time.clock()
tw = time.time()

driver.implicitly_wait(60)  # should halt here for 60s

print "CPU time: ", time.clock() - tc
print "Wall time: ", time.time() - tw

driver.quit()

The script run concludes without any error message, yet the wait statement is entirely ignored.

Output:

CPU time:  0.0
Wall time:  1.1845741272

I have no explanation for this mysterious behavior or any starting point to look for an answer.

I therefore warmly welcome any suggestions or solutions. Thanks!

Upvotes: 2

Views: 868

Answers (1)

alecxe
alecxe

Reputation: 474261

No, implicitly_wait() would not stop/halt the execution at moment you call it. It is called once per session and sets the implicit timeout used while selenium is finding an element or executing a command, quote from the documentation:

implicitly_wait(time_to_wait)

Sets a sticky timeout to implicitly wait for an element to be found, or a command to complete. This method only needs to be called one time per session. To set the timeout for calls to execute_async_script, see set_script_timeout.

I agree that the method name is a bit confusing, set_implicit_timeout() would probably be a better choice.

Also see:

Upvotes: 2

Related Questions