Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97799

Trying to login to Xbox/Microsoft with Selenium, but Log In button never gets pressed

$
0
0

Edit 2:
Based on the accepted answer, I made modifications that were necessary for the code to work. I added expected_conditions because Selenium still couldn't find the element until I did this. Here is the final code replacement for the answer.

log_in = (By.XPATH, '//*[contains(@value, "Sign in")]')
WebDriverWait(driver, 20).until(EC.presence_of_element_located(log_in)).click()

and here is the replacement for my entire login code. You will see that I changed my password field to wait until clickable, and not present. This is because now, the password wasn't getting entered until I did this.

    def login(user, passwd):
        chrome_options = Options()
        chrome_options.add_argument("--headless")
        # chrome_options.add_experimental_option('excludeSwitches', ['enable-logging'])
        driver = Chrome("C:\\bin\\chromedriver", options=chrome_options)
        driver.get(login_url)

        un_field = (By.ID, "i0116")
        pw_field = (By.ID, "i0118")
        next_button = (By.ID, "idSIButton9")

        WebDriverWait(driver, 20).until(EC.presence_of_element_located(un_field)).send_keys(user)

        WebDriverWait(driver, 20).until(EC.element_to_be_clickable(next_button)).click()

        WebDriverWait(driver, 20).until(EC.element_to_be_clickable(pw_field)).send_keys(passwd)

        log_in = (By.XPATH, '//*[contains(@value, "Sign in")]')
        WebDriverWait(driver, 20).until(EC.presence_of_element_located(log_in)).click()


        return driver

ORIGINAL QUESTION
I am using Selenium Webdriver with Chrome to try to login to Microsoft / Xbox Live. I am using explicit waits to wait until an element is present or can be clicked. The problem is, after successfully entering the username, clicking "Next", and entering the password, my program never clicks "Log In", and just continues execution.

    def login(user, passwd):
        chrome_options = Options()
        # chrome_options.add_argument("--headless")
        chrome_options.add_experimental_option('excludeSwitches', ['enable-logging'])
        driver = Chrome("C:\\bin\\chromedriver", options=chrome_options)
        driver.get(login_url)

        un_field = (By.ID, "i0116")
        pw_field = (By.ID, "i0118")
        next_button = (By.ID, "idSIButton9")

        WebDriverWait(driver, 20).until(EC.presence_of_element_located(un_field)).send_keys(user)

        WebDriverWait(driver, 20).until(EC.element_to_be_clickable(next_button)).click()

        WebDriverWait(driver, 20).until(EC.presence_of_element_located(pw_field)).send_keys(passwd)

        WebDriverWait(driver, 20).until(EC.element_to_be_clickable(next_button)).click()

        return driver

I suspect the cause of this issue is the fact that the "Next" button from the previous screen, and the "Log In" button from the password screen have the same element ID, yet I don't get any errors, which puzzles me. I have even tried pressing Return with Keys.RETURN in the password field instead of clicking "Log In" with .click(), but that doesn't work.
Also, when running without headless mode, it almost looks like the next page that I get with my driver later in the code interrupts the login screen, but I can't be sure.

Edit: The page being used is here


Viewing all articles
Browse latest Browse all 97799

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>