Encountered an issue with keyboard interaction and finding a null value for the data-* attribute during automated login attempts on Gmail using Python and Selenium
While attempting to automatically log in to Gmail using Python and Selenium, I successfully sent keys to the username field. However, an error occurred when trying to send keys to the password field: raise exception_class(message, screen, stacktrace) selenium.common.exceptions.ElementNotInteractableException: Message: Element is not reachable by keyboard
This pertains to the latest versions of Selenium and Python 3
Below is my Python code:
def fill_form():
driver = webdriver.Firefox()
#browser initialized
driver.maximize_window()
driver.get("https://gmail.google.com")
driver.implicitly_wait(20) #implicit wait for 20 seconds
# find username and password element in browser
print ("-----------------login------------------")
EMAIL = driver.find_element_by_xpath('//*[@id="identifierId"]')
EMAIL.send_keys("#my mail")
next_stepBTN = driver.find_element_by_xpath('/html/body/div[1]/div[1]/div[2]/div[2]/div/div/div[2]/div/div[2]/div/div[1]/div/span/span')
next_stepBTN.click()
driver.implicitly_wait(20) #implicit wait for 20 seconds
PASSWORD = driver.find_element_by_xpath('/html/body/div[1]/div[1]/div[2]/div[2]/div/div/div[2]/div/div[1]/div/form/span/section/div/span/div[1]/div[1]/div/div/div/div/div[1]/div/div[1]/input')
print("found")
driver.implicitly_wait(20) #implicit wait for 20 seconds
PASSWORD.send_keys("#my password") #failed here
print("send_keys")
In looking for solutions similar to mine, some suggest that using the JS console can help locate elements more accurately. I attempted to locate the password input and change its value in the console. While initially successful in finding the element, it returned null when trying to retrieve the attribute.
var element = document.getElementsByClassName("whsOnd zHQkBf")[0]
element
# result in console below
<input class="whsOnd zHQkBf" type="text" jsname="YPqjbf" autocomplete="off" spellcheck="false" tabindex="0" aria-label="Please enter your password" name="password" autocapitalize="off" dir="ltr" data-initial-dir="ltr" data-initial-value="" badinput="false">
element.getAttribute("data-initial-value")
# Returns null
Although "data-initial-value" changes when entering text in the password field, calling element.getAttribute("data-initial-value") consistently returns null.
I expected the password to be entered automatically via Selenium or JS, but I have tried numerous approaches with no success. Any insights?