我通过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()
我从时间变为导入时间,它给出的错误消失了,现在我得到了:
Traceback (most recent call last):
File "test.py", line 3, in module
from selenium.common.keys import Keys
ImportError: no module named Keys
样品是否过时了?
答案 0 :(得分:11)
来自http://code.google.com/p/selenium/issues/detail?id=1491:
来自selenium.webdriver.common.keys 导入密钥
答案 1 :(得分:0)
看来你的selenium安装不在路径中,在python安装中找到Selenium安装文件夹。类似的东西 C:\ Python33 \ selenv \ LIB \站点包
或使用python安装文件夹中的命令selenv \ Scripts \ python.exe yourseleniumscript.py运行它。
答案 2 :(得分:-2)
复制C:\ Python27 \ Lib \ site-packages \ selenium \ webdriver \ common \ keys.py 到C:\ Python27 \ Lib \ site-packages \ selenium \ common