Search code examples
pythonauthenticationselenium-webdriverfirefox

selenium.webdriver.Firefox not working properly on the login page of nbc.com


I'm using this to auto login on nbc.com, and nbc.com login page is responding with Sorry, we had a problem. Please try again. instead of redirecting to the link provider page. Other than that the page is successfully login me into the site. I'm wandering if this is something in the source of the site that could be causing this to happen or if it is something I'm missing.

from selenium.webdriver.common.by import By

# created this class to use a profile and create it if doesn't exist
from library import Firefox

firefox = Firefox()
firefox.get('https://www.nbc.com/sign-in')

html = firefox.find_element(by = By.TAG_NAME, value = 'html')
form = html.find_element(by = By.TAG_NAME, value = 'form')

for element in form.find_elements(by = By.TAG_NAME, value = 'input'):
    if element.get_attribute(name = 'type') == 'email':
        element.send_keys('[email protected]')
    elif element.get_attribute(name = 'type') == 'password':
        element.send_keys('******')  # noqa

for element in form.find_elements(by = By.TAG_NAME, value = 'label'):
    if element.get_attribute(name = 'class') == 'auth-terms__terms-checkbox':  # noqa
        element.click()
        break

form.find_element(by = By.TAG_NAME, value = 'button').click()

I used the following code to load firefox and logged in manually and I got the same error.

from library import Firefox

firefox = Firefox()
firefox.get('https://www.nbc.com/sign-in')

I also used this to load firefox without a profile and still got the same error.

from selenium.webdriver import Firefox

firefox = Firefox()
firefox.get('https://www.nbc.com/sign-in')

Solution

  • Loading time: Ensure elements have loaded before interaction.You can use

    WebDriverWait
    

    along with expected_conditions to wait for elements to load before interacting with them.

    sometimes Cookies/sessions might be required for login.

    Beforehand check the correct credentials.