Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why does my Selenium script fail on password element?

I have this selenium script that can enter email address, hit the use password button but then fails on entering the password:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time

web = webdriver.Chrome()
web.implicitly_wait(5)
web.get('https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=16&ct=1700481689&rver=7.0.6738.0&wp=MBI_SSL&wreply=https%3a%2f%2foutlook.live.com%2fowa%2f%3fcobrandid%3dab0455a0-8d03-46b9-b18b-df2f57b9e44c%26nlp%3d1%26deeplink%3dowa%252f%26RpsCsrfState%3de98b3d70-89d0-6e78-6a87-b7d5b1245a4e&id=292841&aadredir=1&CBCXT=out&lw=1&fl=dob%2cflname%2cwld&cobrandid=ab0455a0-8d03-46b9-b18b-df2f57b9e44c')

EmailSignIn = web.find_element(By.XPATH,"//*[@id='i0116']")
EmailSignIn.send_keys("generic@live.com")

web.implicitly_wait(5)

EMailSignInContinueButton = web.find_element(By.XPATH, "//*[@id='idSIButton9']")
EMailSignInContinueButton.click()

web.implicitly_wait(5)

UsePasswordButton = web.find_element(By.XPATH, "//*[@id='idA_PWD_SwitchToPassword']")
UsePasswordButton.click()

web.implicitly_wait(5)

SelectEMailPasswordBox = web.find_element(By.XPATH,"//*[@id='i0118']")
SelectEMailPasswordBox.send_keys("FakePassword")

time.sleep(5)

Had no issues with the rest of the script so I am thinking there must be something funky about password boxes I don’t know? Other online information seems outdated. Any help appreciated, thanks!

Tried to run script as above, fails on entering the password. Would like password to be populated in outlook.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Root cause of the issue: No need of the below line. I don’t see anything in the HTML with attribute ID=idA_PWD_SwitchToPassword. (Unless I am missing something, or there is additional screen/button displaying to you but not to me on my system)

UsePasswordButton = web.find_element(By.XPATH, "//*[@id='idA_PWD_SwitchToPassword']")
UsePasswordButton.click()

Check the below working refactored code:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time

web = webdriver.Chrome()
web.maximize_window()
web.get('https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=16&ct=1700481689&rver=7.0.6738.0&wp=MBI_SSL&wreply=https%3a%2f%2foutlook.live.com%2fowa%2f%3fcobrandid%3dab0455a0-8d03-46b9-b18b-df2f57b9e44c%26nlp%3d1%26deeplink%3dowa%252f%26RpsCsrfState%3de98b3d70-89d0-6e78-6a87-b7d5b1245a4e&id=292841&aadredir=1&CBCXT=out&lw=1&fl=dob%2cflname%2cwld&cobrandid=ab0455a0-8d03-46b9-b18b-df2f57b9e44c')
wait = WebDriverWait(web,15)

EmailSignIn = wait.until(EC.element_to_be_clickable((By.XPATH, "//*[@id='i0116']")))
EmailSignIn.send_keys("generic@live.com")

EMailSignInContinueButton = wait.until(EC.element_to_be_clickable((By.XPATH, "//*[@id='idSIButton9']")))
EMailSignInContinueButton.click()

SelectEMailPasswordBox = wait.until(EC.element_to_be_clickable((By.XPATH,"//*[@id='i0118']")))
SelectEMailPasswordBox.send_keys("FakePassword")

time.sleep(20)

Result:

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading