1

I am trying to sign in my account through this link on the Market Watch web page through Python and using the Selenium package. I am able to select the "Sign In" button and click on it but nothing happens and therefore can't access the webpage I want.

I think my mistake comes from the fact that I am perhaps not selecting the correct button. The element code is the following:

<div class="sign-in">
    <button class="solid-button basic-login-submit">
        <span class="text" data-token="signIn" token-title="signIn" title="Sign In">
        Sign In
        </span>
    </button>
</div>
<div class="create-connect" style="display: none;">
    <button class="solid-button basic-login-connect">
        <span class="text" data-token="yesConnect">
        Yes, connect
        </span>
    </button>
    ...some other buttons for facebook connection 

My code is the following:

    driver.get("https://sso.accounts.dowjones.com/login?state=g6Fo2SBQQURPVkxkcTR0RW1zX21NSmxLY3F4Q2RoUm5QTWV4UaN0aWTZMmdhRm8yU0IwUW01dVV6WjJiVXhVUmtaRVRXd3dlamM1UVdjNVIweExiVFJVYlc5WFl3o2NpZNkgNWhzc0VBZE15MG1KVElDbkpOdkM5VFhFdzNWYTdqZk8&client=5hssEAdMy0mJTICnJNvC9TXEw3Va7jfO&protocol=oauth2&prompt=login&scope=openid%20idp_id%20given_name%20family_name%20email%20djid%20prts&response_type=code&redirect_uri=https%3A%2F%2Faccounts.marketwatch.com%2Fauth%2Fsso%2Flogin&nonce=ac689d94-8b8f-4e6d-9255-439f58fc3c0f&connection=DJldap&ui_locales=en-us-x-mw-3-8&ns=prod%2Faccounts-mw#!/signin") #this is the link above 

username = driver.find_element_by_id("username")
password = driver.find_element_by_id("password")

username.send_keys("[email protected]")
password.send_keys("***")

driver.find_element_by_xpath(".//*[contains(text(), 'Sign In')]").click()
driver.find_element_by_xpath(".//*[contains(text(), 'Yes, connect')]").click()

Where the first element is supposed to on the sign in button. I am not sure about the second click but I stilled tried it and still nothing happened.

I am interested to find out:

  1. what am I doing wrong
  2. why when I click on the "Sign In" button nothing happens
  3. how to get over it

I have also tried without success:

driver.find_element_by_css_selector("solid-button.basic-login-submit")
1
  • From the look of the HTML on that page, the <form> has no action attribute, so I bet JavaScript is listening for an onclick or onsubmit event. Clicking this using Selenium might not be triggering DOM events correctly. You might want to try triggering a click event using JavaScript. Commented Apr 5, 2019 at 19:41

4 Answers 4

2

Your try is very close. Changing the code from your attempt to

# You'll need to import these dependencies
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

button = WebDriverWait(driver,1000).until(By.CSS_SELECTOR,"button.solid-button.basic-login-submit")

button.click()

WebDriverWait(0,1000) makes the program search for the element for 1000 seconds. This is better because it gives the page time to load.

Sign up to request clarification or add additional context in comments.

1 Comment

Now it does not work, username.send_keys would also be wrong.
1

Try use following code.This should work.Provide WebdriverWait after inserting value in the test field

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
driver=webdriver.Chrome()
driver.get("https://sso.accounts.dowjones.com/login?state=g6Fo2SBQQURPVkxkcTR0RW1zX21NSmxLY3F4Q2RoUm5QTWV4UaN0aWTZMmdhRm8yU0IwUW01dVV6WjJiVXhVUmtaRVRXd3dlamM1UVdjNVIweExiVFJVYlc5WFl3o2NpZNkgNWhzc0VBZE15MG1KVElDbkpOdkM5VFhFdzNWYTdqZk8&client=5hssEAdMy0mJTICnJNvC9TXEw3Va7jfO&protocol=oauth2&prompt=login&scope=openid%20idp_id%20given_name%20family_name%20email%20djid%20prts&response_type=code&redirect_uri=https%3A%2F%2Faccounts.marketwatch.com%2Fauth%2Fsso%2Flogin&nonce=ac689d94-8b8f-4e6d-9255-439f58fc3c0f&connection=DJldap&ui_locales=en-us-x-mw-3-8&ns=prod%2Faccounts-mw#!/signin") #this is the link above

username = driver.find_element_by_id("username")
password = driver.find_element_by_id("password")

username.send_keys("[email protected]")
password.send_keys("***")
WebDriverWait(driver,5).until(EC.element_to_be_clickable((By.XPATH,"//button[@class='solid-button basic-login-submit']"))).click()

enter image description here

Comments

0

try :

 driver.find_element_by_class_name('sign-in')

Comments

0

Even after the sign in button was clicked I was not signed in. I used the "login" href link from "https://www.marketwatch.com/" and this worked.

from selenium import webdriver
from selenium.webdriver import Firefox
from time import sleep


driver = webdriver.Firefox(executable_path=r'C:\\Py\\geckodriver.exe');

# driver.get('https://sso.accounts.dowjones.com/login?state=g6Fo2SBJbUhZMUdPZlJfOEJSRWgxLVVFNXhoR3E5cFdaVlI4dKN0aWTZMmdhRm8yU0JaV0ZCWVluSmxNM2c0UjJSVk4wNXFlSHByUW5SUU1sRnpjMjFDVkVoeFNno2NpZNkgNWhzc0VBZE15MG1KVElDbkpOdkM5VFhFdzNWYTdqZk8&client=5hssEAdMy0mJTICnJNvC9TXEw3Va7jfO&protocol=oauth2&prompt=login&scope=openid%20idp_id%20roles%20email%20given_name%20family_name%20djid%20djUsername%20djStatus%20trackid&response_type=code&redirect_uri=https%3A%2F%2Faccounts.marketwatch.com%2Fauth%2Fsso%2Flogin&nonce=4b5092ee-62d1-47cb-a16e-2ceb396b059c&connection=DJldap&ui_locales=en-us-x-mw-0&mg=ss-ngx#!/signin')
driver.get('https://accounts.marketwatch.com/login?target=https%3A%2F%2Fwww.marketwatch.com%2F')

sleep(5)

username = driver.find_element_by_id("username")
password = driver.find_element_by_id("password")

username.send_keys("[email protected]")
password.send_keys("***")

sign_in = driver.find_element_by_xpath(".//*[@id='basic-login']/div[1]/form/div/div[7]/div[1]/button")

sign_in.click()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.