我通过pip在windows机器上安装了selenium.
只需在网站上试用样本:
http://pypi.python.org/pypi/selenium
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.common.keys import Keys
import time
browser = webdriver.Firefox() # Get local session of firefox
browser.get("http://www.yahoo.com") # Load page
assert browser.title == "Yahoo!"
elem = browser.find_element_by_name("p") # Find the query box
elem.send_keys("selenium" + Keys.RETURN)
time.sleep(0.2) # Let the page load, will be added to the API
try:
browser.find_element_by_xpath("//a[contains(@href,'http://seleniumhq.org')]")
except NoSuchElementException:
assert 0, "can't find seleniumhq"
browser.close()
Run Code Online (Sandbox Code Playgroud)
我从时间变为导入时间,它给出的错误消失了,现在我得到了:
Traceback (most recent call last):
File "test.py", line 3, in module
from …Run Code Online (Sandbox Code Playgroud)