Somehow send_keys enters repeat password or string other than mentioned password leading login failure.
Tried adding explicit wait(), driver.clear() but does not work.
Here is a sample code in Python –
Approach 1 –
driver = webdriver.chrome(executable path) driver.maximize__window() driver.get(address) password = "xyz" field1 = wait.until(EC.presence_of_element_located(By.XPATH, <xpath of the password field>) actionChains.move_to_element(field1).click() actionChains.move_to_element(field1).send_keys(password).perform() driver.find_element(By.ID, "Login-button").click()
Here instead of “xyz” probably “xyzxyzxyzx” string gets added to the password field(cannot decode as password gets masked).
Please suggest.
Approach 2 –
Also, another try with below code somehow concatenates username to the password while entering password.
username = driver.find_element(By.ID,"USERNAME").click() actionChains.send_keys("test") password = driver.find_element(By.ID,"PASSWORD").click() actionChains.send_keys("xyz") actionChains.perform()
This snippet results into –
Username as “test”
Password as “testxyz”
Expected output is:
Username as “test”
Password as “xyz”
Advertisement
Answer
Sometimes it auto fills the last input. I get around it by just adding “Keys.BACK_SPACE*20” into the send keys brackets
.send_keys(Keys.BACK_SPACE*20, "xyz")
you will also need to import the Keys library:
from selenium.webdriver.common.keys import Keys