Home > other >  How can I best adapt my Selenium code to enter username and password securely?
How can I best adapt my Selenium code to enter username and password securely?

Time:04-22

I am entering login details onto a website using Selenium. The username element is:

<input  id="j_username" name="j_username" type="text" autocapitalize="off" autofocus="autofocus" aria-labelledby="usernamelabel">

and the password element is:

<input  id="j_password_pseudo" name="j_password_pseudo" type="password" maxlength="47" aria-labelledby="passwordlabel" role="application">

I currently have the following code for entering the username and password:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, "j_username"))).send_keys("Username")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, "j_password_pseudo"))).send_keys("Password")

Can anyone suggest a better way of writing this code for entering a username and password?.

CodePudding user response:

Like the above mention that's the pretty standard way of logging in,

Based on what your showing as your Element Id use WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "j_password_pseudo"))).send_keys("Password")'

instead of NAME

if your looking to keep your username & password secure outside your code, you could place them in a YMAL file for python to decode and assign to local variables or an encrypted txt file to assign the user name and password

other method using the Import os library for capturing user name if its the same as your local environment would be username = os.environ.get('USERNAME')

hope this helps

  • Related