Reputation: 41
I am attempting to log into my Google account using selenium in python. I keep coming across the following error:
selenium.common.exceptions.ElementNotInteractableException: Message: Element <input class="whsOnd zHQkBf" name="password" type="password"> is not reachable by keyboard
I've looked at some other similar questions, but most of them are about failed authentication. Another post suggested looking for something covering it but I didn't see anything. Also, the input box is not hidden as per its html:
<input type="password" class="whsOnd zHQkBf" jsname="YPqjbf" autocomplete="current-password" spellcheck="false" tabindex="0" aria-label="Enter your password" name="password" autocapitalize="off" dir="ltr" data-initial-dir="ltr" data-initial-value="" badinput="false">
I've also tried putting some wait statements before accessing the password input box with no luck. I also checked to make sure there was only 1 element being returned by the find_elemnt_by function.
To make sure I was doing it properly I tested it with Amazon and it worked perfectly, so not sure why Google's is being difficult.
Here is my code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
# create a new Firefox session
driver = webdriver.Firefox(executable_path="D:\Selenium\geckodriver.exe")
driver.implicitly_wait(5)
# Navigate to youtube
driver.get("https://www.youtube.com/")
sign_in_button = driver.find_element_by_css_selector('ytd-button-renderer.style-scope:nth-child(5)')
sign_in_button.click()
username = driver.find_element_by_css_selector('#identifierId')
username.send_keys('[email protected]')
next_button = driver.find_element_by_css_selector('#identifierNext')
next_button.click()
password_text_box = driver.find_element_by_css_selector('.I0VJ4d > div:nth-child(1) > input:nth-child(1)')
# FAILS HERE
password_text_box.send_keys('fakepassword')
next_password_button = driver.find_element_by_css_selector('#passwordNext')
next_password_button.click()
Any suggestions?
Upvotes: 3
Views: 2303
Reputation: 51
I had a similar issue, and did the following:
1) I first used the "find_element_by_css_selector" function, which selects the first occurence of the element with given attributes. This did not work.
2) Then I used the "find_elements_by_css_selector" (notice the s), which returns a list of the elements with given attributes. There was 2 elements in that list. Of course the first one (with index [0]) was not accessible by keyboard: this is equivalent of doing (1) above. But the second element (with index [1]) was accessible by keyboard. Problem solved.
Upvotes: 0
Reputation: 41
I'm putting this here in case anyone comes across this problem themselves.
I couldn't resolve the logging in issue directly, but I found a workaround.
I had tried using cookies before but was doing something wrong, so instead, I just copied my Firefox profile (which has the auth cookie for google saved) and attached it to the webdriver.
ffp = FirefoxProfile(r"C:\Users\user\AppData\Roaming\Mozilla\Firefox\Profiles\sel_test")
driver = webdriver.Firefox(executable_path="D:\Selenium\geckodriver.exe", firefox_profile=ffp)
Upvotes: 1