Selenium Unable to Import Keys

I’ve tried searching here a few times for a relevant thread but have not been able to find anything. Not sure if it’s an issue with how I installed selenium/ version etc. Below is the code I’m trying to run along with the error I received.

Any help is greatly appreciated. Thank you!

Code:

import selenium
from seleniumimport webdriver
from selenium.webdriver.common.keysimport keys
import time

class TwitterBot:
def \_init\_(self,username,password):
self.username = username
self.password = password
self.bot = webdriver.Firefox()

def login(self):
bot =self.bot
bot.get('https://twitter.com/')
time.sleep(3)
email = bot.find_element_by_class_name('js-username-field email-input js-initial-focus')
password = bot.find_element_by_class_name('js-password-field')
email.clear()
password.clear()
email.send_keys(self_username)
password.send_keys(self.password)

ducks = TwitterBot('iheartduckss@outlook.com', '\*\*\*\*\*\*\*\*\*')
ducks.login()

Error:

from selenium.webdriver.common.keys import keys
ImportError: cannot import name ‘keys’ from ‘selenium.webdriver.common.keys’ (/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/common/keys.py)

Please anyone help here, i am alsogetting same error.

E:\Seleniumpython\venv\Scripts\python.exe E:/Seleniumpython/multibrowser.py
Traceback (most recent call last):
File “E:/Seleniumpython/multibrowser.py”, line 6, in <module>
driver=webdriver.chrome(executable_path=“E:\Driver\chromedriver_win32\chromedriver”)
TypeError: ‘module’ object is not callable

1 Like

Hey, may be this could help:

from selenium.webdriver.common.keys import Keys

k is capitals in Keys… check if it works

13 Likes

Thanks man Its really worked.

Finally can work on the facebook bot i was on making.

Again man thanks a lot.

Had the same issue but worked as you suggested (K not k). Thanks. 

hello i have a problem when try run my code, you can help? below my code and message error.

thanks.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import random

class InstagramBot:
    def __init__(self, username, password):
        self.username = username
        self.password = password
        self.bot = webdriver.Firefox(executable_path=r"C:\Users\Geovane\Desktop\geckodriver\geckodriver.exe")

    def long (self):
        bot = self.bot
        bot.get(“https://www.instagram.com”)

PS C:\Users\Geovane\Desktop\igBot> & C:/Users/Geovane/AppData/Local/Programs/Python/Python38-32/python.exe c:/Users/Geovane/Desktop/igBot/igbot.py
Traceback (most recent call last):
File “c:/Users/Geovane/Desktop/igBot/igbot.py”, line 1, in <module>
from selenium import webdriver
File “C:\Users\Geovane\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver__init__.py”, line 18, in <module>
from .firefox.webdriver import WebDriver as Firefox # noqa
File “C:\Users\Geovane\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py”, line 36, in <module>
from .service import Service
File “C:\Users\Geovane\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\firefox\service.py”, line 21, in <module>
class Service(service.Service):
AttributeError: module ‘selenium.webdriver.common.service’ has no attribute ‘Service’
PS C:\Users\Geovane\Desktop\igBot>