1

I'm attempting to use Selenium with Python to sign in to a webpage. I've gotten to the point where I can successfully the username and password. Initially I tried just using the "Enter" key from the password field like so -

passwordField = browser.find_element_by_css_selector('#password')
passwordField.send_keys(Keys.ENTER)

This doesn't work for me, even though pressing "Enter" while my cursor is in the password field signs me in just fine.

 

So now I'm trying to click the sign in button, but my problem is that I can't seem to locate the element properly.

In the Chrome console, the button is listed as such (new lines added for readability) -

<button class="btn__primary--large from__button--floating mercado-button--primary"
data-litms-control-urn="login-submit"
type="submit" aria-label="Sign in">Sign in</button>

The class name contains spaces, so I attempted this -

signInButton = browser.find_element_by_class_name('btn__primary--large from__button--floating mercado-button--primary')
signInButton.click()

Unfortunately Selenium can't find that element -

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".btn__primary--large from__button--floating mercado-button--primary"}

How can I target this sign in button?

 

Edit: here's the web address - https://www.linkedin.com/login?fromSignIn=true&trk=guest_homepage-basic_nav-header-signin

4
  • What website is it? Commented Aug 31, 2020 at 21:52
  • @arundeepchohan I didn't know if it would be inappropriate to name the website, but it's LinkedIn, after clicking the sign in button on the home page. Commented Aug 31, 2020 at 21:54
  • Please provide a website link to test out the script. Because on some websites the html is rendered at run time and it can't be seen on view source. On the other hand some elements don't allow clicking and we've to find the parent to that child to perform click. Commented Aug 31, 2020 at 22:02
  • @HassaanAli thank you. I wasn't sure if it was appropriate to include the website. I've edited the post to contain the address (LinkedIn.com, after clicking sign in on the home page) Commented Aug 31, 2020 at 22:04

2 Answers 2

1

Apparently it tries to treat the whole string as one class however these are multiple classes. Have you tried with passing in only one class name? Although it is possible that it would find multiple items. Probably you'd be better of looking for an #id instead?

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

2 Comments

This worked for me! I just used the first class name. I was thinking the entire string, including spaces, was the class name. Thank you! Though on a side note, I don't see an ID for the element.
Right, yes, there is no ID. Another idea could have been the aria-label attribute perhaps. Anyways, it's good it worked.
0

Try using the following to get the element by class and clicking it.

 driver.find_element_by_class_name("mercado-button--primary").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.