2

I have a specific login button I can't access with Python Firefox Selenium. It's the login button on this webpage: https://schalter.asvz.ch/tn/lessons/39616

I'm running Ubuntu 16.04, Python 3.5.2, Firefox 65.0 and Selenium 3.141.

I tried several combinations of approaches I found here on stackoverflow including the following:

login = driver.find_element_by_xpath("//*[@class='btn btn-default ng-star-inserted']")

login = driver.find_element_by_xpath("//button[@class='btn btn-default ng-star-inserted']")

login = driver.find_element_by_class_name('btn btn-default ng-star-inserted')

login = driver.find_element_by_xpath("//*[contains(., 'Login')]")

login = driver.find_element_by_name('app-lessons-enrollment-button')

But none of them worked. Always resulting in:

NoSuchElementException: Message: Unable to locate element: //*[@class='btn btn-default ng-star-inserted']

What is so different with this button? How can I make it work?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
pixelpress
  • 109
  • 1
  • 14

4 Answers4

2

This error message...

NoSuchElementException: Message: Unable to locate element: //*[@class='btn btn-default ng-star-inserted']

...implies that the ChromeDriver was unable to locate the desired element through the locator you have used.


Virtually, your first two(2) locators were just perfecto.

However, the desired element is an Angular element so to locate the element you have to induce WebDriverWait for the element to be clickable and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.btn.btn-default.ng-star-inserted[title='Login']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='btn btn-default ng-star-inserted' and @title='Login']"))).click()
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

Try the below option.

Login=driver.find_element_by_css_selector("button.ng-star-inserted")

Or try this

WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,'button.ng-star-inserted'))).click()

You need following imports for option 2.

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
KunduK
  • 32,888
  • 5
  • 17
  • 41
0

Try the below xpath:

xpath = "//button[@title='Login']"
element = driver.find_element_by_xpath(xpath);
element.click();
Ali
  • 1,689
  • 1
  • 5
  • 12
0

Following xpath works just fine (tested using selenium java)

//button[@title='Login']

I was able to locate and click the button.

Matthewek
  • 1,519
  • 2
  • 22
  • 42