Skip to content
Advertisement

Incorrect password string gets entered by send_keys in selenium python

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 –

JavaScript

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.

JavaScript

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

JavaScript

you will also need to import the Keys library:

from selenium.webdriver.common.keys import Keys

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement