Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python selenium示例没有';不起作用,没有名为Keys的模块_Python_Selenium - Fatal编程技术网

python selenium示例没有';不起作用,没有名为Keys的模块

python selenium示例没有';不起作用,没有名为Keys的模块,python,selenium,Python,Selenium,我通过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

我通过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

样本是否已过期?

复制C:\Python27\Lib\site packages\selenium\webdriver\common\keys.py 到C:\Python27\Lib\site packages\selenium\common

来自:

来自selenium.webdriver.common.keys 导入密钥


似乎您的selenium安装不在路径中,请在python安装中查找selenium安装文件夹。类似于
C:\Python33\selenv\Lib\site包


或者从python安装文件夹中使用命令selenv\Scripts\python.exe yourseleniumscript.py运行它。

问题在于硒的版本控制。您的建议将允许导入(可能),但将破坏使用其新父模块导入keys.py的任何内容。