Skip to content

Instantly share code, notes, and snippets.

@hugs
Created February 9, 2009 10:43
Show Gist options
  • Save hugs/60740 to your computer and use it in GitHub Desktop.
Save hugs/60740 to your computer and use it in GitHub Desktop.
Getting Started with Selenium 2.0 (WebDriver)
# Using Selenium 2 and its native Python bindings for the first time...
# On Ubuntu 8.04 and Python 2.5.2
"""
# Checkout
$ svn checkout http://selenium.googlecode.com/svn/webdriver/trunk/ webdriver
# Build the code
$ cd webdriver
$ sudo python setup.py build
# Some hacking until the Python bindings are packaged as a real Python library
$ export WEBDRIVER=.
$ export PYTHONPATH=$PYTHONPATH:firefox/lib-src:build/lib
# Let's sling some code
$ python
"""
# Some imports
from webdriver_firefox.webdriver import WebDriver
# Create a "driver" object that will do all the real work.
driver = WebDriver()
# Open a web page
driver.get("http://google.com")
# Find the search box
search_box = driver.find_element_by_name("q")
search_box.send_keys("Hello, World!")
# Submit the query...
search_button = driver.find_element_by_name("btnG")
search_button.click()
# Say goodbye
driver.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment