2017-05-07 107 views
1

導入密鑰我試圖執行下面的代碼。我專門嘗試從webdriver導入Keys,但它仍然不起作用。需要幫助從selenium.webdriver.common.keys

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 
>>> 

回答

3

你需要有這個

from selenium.webdriver.common.keys import Keys代替

import selenium.webdriver.common.keys

,然後你的代碼將運行正常。

+0

工程就像一個魅力!謝謝!!! –