2. Getting Started — Selenium Python Bindings 2 documentation

2.1. Simple Usage

If you have installed Selenium Python bindings, you can start using it from Python like this.

from selenium import webdriver
from selenium.webdrivermon.keys import Keys
from selenium.webdrivermon.by import By

driver = webdriver.Firefox()
driver.get("http://www.python")
assert "Python" in driver.title
elem = driver.find_element(By.NAME, "q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()

The above script can be saved into a file (eg:- python_org_search.py), then it can be run like this:

python python_org_search.py

The python which you are running should have the selenium module installed.

 

更多推荐

selenium python 入门教程