'After replacing my find_element_by_*() function calls with find_element(by=By.*), my automated login stopped working. Any ideas why?

Basically, I am trying to login to a website using a Selenium WebDriver. Based on the deprecation warnings I was getting when running my code, I changed the function calls.

From:

# Old login code
username = 'username'
password = 'password'

driver.find_element_by_id("u").send_keys(username)
driver.find_element_by_id("p").send_keys(password)

button = driver.find_element_by_xpath("//button[text()='Login']")
button.click()

To:

# New login code
username = 'username'
password = 'password'

driver.find_element(by=By.ID, value='u').send_keys(username)
driver.find_element(by=By.ID, value='p').send_keys(username)

button = driver.find_element(by=By.XPATH, value="//button[text()='Login']")
button.click()

Now, my selenium web driver fails to login at the very same link. Does anyone know what is going on? Things I should check for? I understand this issue might be specific to the website I am trying to login to.

For now, I'm just planning to keep the old code, but would love to get this fixed.



Sources

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

Source: Stack Overflow

Solution Source