Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
136 lines (88 sloc) 4.52 KB

Appendix: Frequently Asked Questions

Another FAQ:

How to use ChromeDriver ?

Download the latest chromedriver from download page. Unzip the file:


You should see a chromedriver executable. Now you can create an instance of Chrome WebDriver like this:

driver = webdriver.Chrome(executable_path="/path/to/chromedriver")

The rest of the example should work as given in other documentation.

Does Selenium 2 support XPath 2.0 ?


Selenium delegates XPath queries down to the browser's own XPath engine, so Selenium support XPath supports whatever the browser supports. In browsers which don't have native XPath engines (IE 6,7,8), Selenium supports XPath 1.0 only.

How to scroll down to the bottom of a page ?


You can use the execute_script method to execute javascript on the loaded page. So, you can call the JavaScript API to scroll to the bottom or any other position of a page.

Here is an example to scroll to the bottom of a page:

driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

The window object in DOM has a scrollTo method to scroll to any position of an opened window. The scrollHeight is a common property for all elements. The document.body.scrollHeight will give the height of the entire body of the page.

How to auto save files using custom Firefox profile ?



The first step is to identify the type of file you want to auto save.

To identify the content type you want to download automatically, you can use curl:

curl -I URL | grep "Content-Type"

Another way to find content type is using the requests module, you can use it like this:

import requests
content_type = requests.head('').headers['content-type']

Once the content type is identified, you can use it to set the firefox profile preference: browser.helperApps.neverAsk.saveToDisk

Here is an example:

import os

from selenium import webdriver

fp = webdriver.FirefoxProfile()

fp.set_preference("", os.getcwd())
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream")

browser = webdriver.Firefox(firefox_profile=fp)

In the above example, application/octet-stream is used as the content type.

The option specify the directory where you want to download the files.

How to upload files into file inputs ?

Select the <input type="file"> element and call the send_keys() method passing the file path, either the path relative to the test script, or an absolute path. Keep in mind the differences in path names between Windows and Unix systems.

How to use firebug with Firefox ?

First download the Firebug XPI file, later you call the add_extension method available for the firefox profile:

from selenium import webdriver

fp = webdriver.FirefoxProfile()

fp.set_preference("extensions.firebug.currentVersion", "1.8.4") #Avoid startup screen
browser = webdriver.Firefox(firefox_profile=fp)

How to take screenshot of the current window ?

Use the save_screenshot method provided by the webdriver:

from selenium import webdriver

driver = webdriver.Firefox()