Failed to interact with keybord and .getAttribute returning null for data-* attribute when I tried to login gmail automatically using python and selenium
I was trying to login gmail automatically using python and selenium. The first step which is sending keys to username field was successful but there is a error raised when I tried to send keys to password field: raise exception_class(message, screen, stacktrace) selenium.common.exceptions.ElementNotInteractableException: Message: Element is not reachable by keyboard
This is for a latest selenium and python 3
here is my python code:
def fill_form():
driver = webdriver.Firefox()
#browser initiallized
driver.maximize_window()
driver.get("https://gmail.google.com")
driver.implicitly_wait(20) #gives an 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) #gives an 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) #gives an implicit wait for 20 seconds
PASSWORD.send_keys("#my password") #failed here
print("send_keys")
I was looking for some other problems which is similar to mine and some people suggest that using JS console can locate element more precisely. Then I tried to locate password input and change it value in console. It went well at the beginning, which I can find the element; but it returns null when I getAttribute
var element = document.getElementsByClassName("whsOnd zHQkBf")[0]
element
# console result is 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")
# And this is reurning null
I can see "data-initial-value" is changable when I enter something in the password field but element.getAttribute("data-initial-value") always return null.
I expect the password can be entered by the keyboard automatically using selenium or JS. I tried many ways and I can't see what the logic of login is. Anyone???