1

website:https://www.etoro.com/login

<button automation-id="login-sts-btn-sign-in" ng-click="loginCtrl.login(loginForm)" class="e-btn-big wide dark pointer">Sign in</button>

I am trying to click on Sign in button by xpath :

driver.find_element_by_xpath("/html/body/ui-layout/div/div/div[1]/login/login-sts/div/div/div[1]/form/div/div[4]/button").click()

But failed to do so. Tried by css and by class also but unable to login.

When I am trying to login manually then it login successfully but while through selenium python it failed to do so.

Page only showing an error: "An error occurred ,please try again" Is there any suggestions, what to do or what I am not getting here?

João Farias
11.2k2 gold badges21 silver badges41 bronze badges
asked Dec 21, 2018 at 9:29
1
  • Okay, first of all a small piece of advice, separate the selector logic from the actions you're performing on them. To the actual issue, do you do anything else bevor you interact with the element? Since the selectors from João Farias answer don't seem to work I'd assume a timing issue here, especially since it's a completely dynamically build pagte so you need to give the browser some rendering time until you define and use the elements. Could you just put a time.sleep(10) before you click the button and tell me if that works? If yes I'll add an answer detailing how to handle pages like that Commented Sep 12, 2020 at 23:01

3 Answers 3

0

You can use the CSS attribute specially placed for automation:

button[@automation-id='login-sts-btn-sign-in'] // XPath
button[automation-id='login-sts-btn-sign-in'] // CSS Selector

If it does not work, please, update your question with the Python code that selects and clicks on the element.

answered Dec 21, 2018 at 9:36
2
  • I have tried both :'button = driver.find_elements_by_xpath("//button[@automation-id='login-sts-btn-sign-in']").click()' and 'button = driver.find_element_by_css_selector("button[automation-id='login-sts-btn-sign-in']").click()' But it does not works. Commented Dec 21, 2018 at 11:10
  • What was the error? Add a breakpoint between the find call and the click and inspect of the is visible. Also, add another break point after the click, to check if the click is happening. You may need to add some waits before find or after click. Commented Dec 22, 2018 at 13:38
0

Try this out

You can find all buttons by text and then execute click() method for each button in a for loop.

Using this SO answer it would be something like this:

buttons = driver.find_elements_by_xpath("//*[contains(text(), 'Sign in')]")
for btn in buttons:
 btn.click()
answered Dec 21, 2018 at 9:53
13
  • @vermin len(buttons)=2 :Tried both of them but still getting the same error that "An error has occurred please try again" , Do not getting that what can be the reason for that. . . Please suggest any other method would be thankful to you.. Commented Dec 21, 2018 at 11:17
  • okay so exactly when the error is occuring like when you trying to click the button or before that Commented Dec 21, 2018 at 11:19
  • After clicking the button error occurs on the page. Using driver=webdriver.Firefox(), and used chromedriver() too but error still the same for both Commented Dec 21, 2018 at 11:22
  • i dont find this error related to either python nor does with selenium Commented Dec 21, 2018 at 12:05
  • 1
    You can check url by manually sign in by provided user details.. if it works? Commented Dec 21, 2018 at 12:28
0

This worked perfectly for me:

driver.find_element_by_xpath('//button[@automation-id="login-sts-btn-sign-in"]').click()
answered Nov 7, 2020 at 17:56

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.