我正在尝试执行以下代码。我专门尝试从webdriver导入密钥,但它仍然无法正常工作。
from selenium import webdriver
import selenium.webdriver.common.keys
driver = webdriver.Firefox()
page = driver.get("https://www.python.org/")
print (driver.title)
finder = driver.find_element_by_class_name("search-field")
finder.send_keys("Python Test")
finder.send_keys(Keys.RETURN)
输出:
Welcome to Python.org
Traceback (most recent call last):
File "C:/Users/Arvind/Desktop/Python Tests/selenium_tests.py", line 9, in
<module>
finder.send_keys(Keys.RETURN)
NameError: name 'Keys' is not defined
>>>
答案 0 :(得分:12)
你需要这个
from selenium.webdriver.common.keys import Keys
而不是
import selenium.webdriver.common.keys
然后你的代码运行正常。