'Unable to retrieve element id for password field on login.microsoftonline.com page

The login process to https://login.microsoftonline.com was working fine until this weekend.

I was able to select the username by id and can pass the keys but the problem is with the password field.

This is the element i used for password

Driver.FindElementByXPath("//*[@id=\"passwordInput\"]");

I tried some other ways but they didn't work

Driver.FindElementByXPath("//*[@id=\"i0118\"]");

Driver.FindElementByXPath("//*[contains(text(), 'Password')]");

Here's the error that I got: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="passwordInput"]"}

(when I used id=passwordInput)



Solution 1:[1]

If you look at the HTML code of the site, you will see that the password field is

<input name="passwd" type="password" id="i0118" autocomplete="off" etc.>

so to target the element you can use input[type=password]

See code below for the implementation

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome(service=Service('your_chromedriver_path'))

driver.get('https://login.microsoftonline.com/')
# sets a maximum waiting time for .find_element() and similar commands
driver.implicitly_wait(10)

driver.find_element(By.CSS_SELECTOR, 'input[type=email]').send_keys('[email protected]')
driver.find_element(By.CSS_SELECTOR, 'input[type=submit]').click()
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "input[type=password]"))).send_keys('some_password')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sound wave