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.

Upvotes: 5

Views: 12330

Answers (2)

Purushottam
Purushottam

Reputation: 31

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

Upvotes: 3

Dane White
Dane White

Reputation: 3542

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

Upvotes: 10

Related Questions