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?

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
    – Daniel
    Sep 12, 2020 at 23:01

4 Answers 4

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.

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.
    – Shiv
    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. 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()
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..
    – Shiv
    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
    – Rao
    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
    – Shiv
    Dec 21, 2018 at 11:22
  • i dont find this error related to either python nor does with selenium
    – Rao
    Dec 21, 2018 at 12:05
  • 1
    You can check url by manually sign in by provided user details.. if it works?
    – Shiv
    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()
0

It seems like the problem is not with the XPath, CSS or class that you are using to find the sign-in button, but rather with the login functionality itself. When you try to login manually, it works fine, but when you try to login using Selenium Python, it fails with an error message.

Here are some suggestions you can try:

1 Wait for the element to be clickable: Sometimes, the element may not be clickable immediately after it loads on the page. You can wait for the element to become clickable by using an explicit wait condition. You can use the ExpectedConditions.element_to_be_clickable method to wait for the element to become clickable. Here's an example:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

wait = WebDriverWait(driver, 10)
element = wait.until(EC.element_to_be_clickable((By.XPATH, "/html/body/ui-layout/div/div/div[1]/login/login-sts/div/div/div[1]/form/div/div[4]/button")))
element.click()

This will wait for a maximum of 10 seconds for the element to become clickable. You can adjust the timeout value as per your requirement.

2 Try logging in with valid credentials: Sometimes, the website may block automated login attempts with invalid credentials. Make sure that you are using valid credentials to login.

3 Try disabling browser automation detection: Some websites may detect and block automated login attempts. You can try disabling browser automation detection by setting the navigator.webdriver property to False. Here's an example:

driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")

This will disable the navigator.webdriver property, which is used by websites to detect browser automation.

4 Try using a different browser: Sometimes, the website may have issues with certain browsers. You can try using a different browser to see if it works.

I hope these suggestions help you resolve the issue.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.