Python Selenium unable to login by clicking on Button inside a form

Viewed 2050

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

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

Code trial:

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?

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

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()

Expected result would be a successfull login and render to the dashboard of my account.

2 Answers

To send a character sequence to a Username and Password field's, and also invoke a click() on an element with text as Sign in as value ,you need to induce a WebDriverWait for the element to be clickable and after that you will be able to use the following solution:

  • Code Block:

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    driver= webdriver.Firefox(executable_path=r'C:\Utility\BrowserDrivers\geckodriver.exe')
    driver.get("https://www.etoro.com/login")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.w-login-main-form-input.ng-valid-email.ng-invalid-required.ng-valid-pattern"))).send_keys("Etoro")
    driver.find_element_by_css_selector("input.w-login-main-form-input[type='password']").send_keys("Test")
    driver.find_element_by_css_selector("button.e-btn-big.wide.dark.pointer[automation-id='login-sts-btn-sign-in']").click()
    
  • Browser Snapshot:

etoro

You need to install chromedriver and chrome. You can change these settings for other browsers if you want. This work fine for me.

My OS: Ubuntu 16.04

from selenium import webdriver

browser = webdriver.Chrome("/usr/lib/chromium-browser/chromedriver")

browser.get('<login_url>')

username = browser.find_element_by_name("<username_name_tag>")
password = browser.find_element_by_name("<password_name_tag>")

username.send_keys("<username>")
password.send_keys("<password>")

browser.find_element_by_xpath("//button[@automation-id='login-sts-btn-sign-in' and @value='Sign in']").click() 
Related