简体   繁体   中英

Python code run error Need help. It gives error that "cannot import name 'keys'"

from selenium import webdriver
from selenium.webdriver.common.keys import keys

driver = webdriver.firefox()
driver.get ("http://www.python.org")

Error message:

Traceback (most recent call last):
  File "C:/pselenium/sample.py", line 2, in <module>
    from selenium.webdriver.common.keys import keys
ImportError: cannot import name 'keys' from 'selenium.webdriver.common.keys' (C:\Python37\lib\site-packages\selenium\webdriver\common\keys.py)

I traced the path manually and all the file names and path are correct. I dont know what is the problem.

You should only specify "keys" once:

from selenium.webdriver.common import keys

Edit:

Are you trying to import "Keys" (capitalized)

from selenium.webdriver.common.keys import Keys

from selenium import webdriver ( all in small letters )

from selenium.webdriver.common. keys import Keys

(first letter in first keyword 'keys' must be small and first letter in second keyword 'Keys' must be in capital).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM