Reputation: 5
I am making an instagram bot in python and it used to work properly until today for some reason. When I pass the username and the password to the send_keys() function, it tells me that the element is not reachable by keyboard. Here's the full error message :
Traceback (most recent call last): File "main.py", line 28, in login_insta(driver, usr, pwd) File "/home/unknown/Documents/code/python/instats/login_profile.py", line 14, in login_insta usr_box.send_keys(username) File "/home/unknown/.local/lib/python3.5/site-packages/selenium/webdriver/remote/webelement.py", line 352, in send_keys 'value': keys_to_typing(value)}) File "/home/unknown/.local/lib/python3.5/site-packages/selenium/webdriver/remote/webelement.py", line 501, in _execute return self._parent.execute(command, params) File "/home/unknown/.local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 311, in execute self.error_handler.check_response(response) File "/home/unknown/.local/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.ElementNotInteractableException: Message: Element is not reachable by keyboard
This is the function that doesn't work :
def login_insta(driver, username, password):
login = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "/html/body/span/section/main/article/div[2]/div[2]/p/a")))
login.click()
usr_box = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "/html/body/span/section/main/article/div[2]/div[1]/div/form/div[1]/div/div[1]/label")))
pwd_box = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "/html/body/span/section/main/article/div[2]/div[1]/div/form/div[2]/div/div[1]/label")))
usr_box.send_keys(username)
pwd_box.send_keys(password)
login_button = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "/html/body/span/section/main/article/div[2]/div[1]/div/form/span/button")))
login_button.click()
Can anyone help me please ?
Upvotes: 0
Views: 1724
Reputation: 642
Long XPaths like those are very prone to breaking when there are minor changes in the page's code.
Try these XPaths instead:
'//input[@type="text"]' // username or phone number
'//input[@type="password"]' // password
'//button[contains(text(), "Log in")]' // log in button
Upvotes: 0