June 01, 2011
Selenium's WebDriver & Python: Dealing with script timeouts
Selenium's WebDriver is a great way to interact with web sites in an automated way. It's primarily for testing, though I've also had occasion to use it for other purposes (with the permission of the relevant site owners).
I searched the web for solutions and found various suggestions that didn't work. Perhaps many of them worked with pre-WebDriver versions of Selenium, I don't know.
In any case, the following worked for me to change the timeouts to 10 minutes:
from selenium import webdriver
profile = webdriver.firefox \
set_pref = profile.set_preference
driver = webdriver.Firefox(fx_profile=profile)
Note that the dom.max_chrome_script_run_time preference has nothing to do with Google Chrome, it's related to Firefox's internal Chrome URL's. In fact, for my purposes, I only needed to change dom.max_chrome_script_run_time.
Note: if you're not familiar with WebDriver, do help(webdriver.Firefox) for a description of the methods you have available for interacting with sites. Hint: the oddest thing is that to fill in a text field, you get an object representing the element with the text field, and then call myElement.send_keys("the text").
Update: Docs on the Python bindings may be found here.