gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 20:10:58 24 4
gpt4 key购买 nike

我在 Windows 机器上通过 pip 安装了 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

样本是否过时?

最佳答案

来自 http://code.google.com/p/selenium/issues/detail?id=1491 :

from selenium.webdriver.common.keys import Keys

关于python selenium 示例不起作用,说没有名为 Keys 的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5503489/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com