1

I am new to Selenium. I am using Selenium 3.141 from anaconda on OSX. My Chrome version is 71.0 and Chromedriver version is 2.45. My goal is to use Selenium to click on a button with "Accept" on it on a webpage. I am able to instantiate the webdriver object using the executable and use the same to load the page in question. I then have a wait for 20 seconds. It's the next bit that fails. Code is unable to find the element that has to be clicked on. Attached are two images of elements associated with the button at various levels and sublevels with highlighted parts from inspection. I have tried variants such as

accept_button = driver.find_element_by_class_name('flex-x.static.h- center.v-center.bt-button.filled')

and

accept_button = driver.find_element_by_class_name('Accept')

and a few others to no avail. Please help.

Button frame:

button frame

Accept rectangle:

accept rectangle

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Titanical
  • 45
  • 1
  • 2
  • 9

3 Answers3

0

did you see bt-button.Accept.ng-isolate-scope.focused you can use it for selecting using css selector

accept_button = driver.find_element_by_css_selector('bt-button.Accept.ng-isolate-scope.focused')
# or
accept_button = driver.find_element_by_css_selector('bt-button.Accept')
ewwink
  • 18,382
  • 2
  • 44
  • 54
  • I tried both and am getting "selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: ...." – Titanical Dec 28 '18 at 03:25
0

The desired element is an Angular element so to locate/click you have to induce WebDriverWait for the element to be clickable and you can use either of the following solutions:

  • Using CSS_SELECTOR:

    accept_button = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "bt-button.Aceept.ng-isolate-scope[mutable-label='prelogin.translations.Accept']")))
    
  • Using XPATH:

    accept_button = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//bt-button[@class='Aceept ng-isolate-scope focused' and @mutable-label='prelogin.translations.Accept']")))
    
  • 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
  • I tried both and am getting a timeout exception from wait.py – Titanical Dec 28 '18 at 03:25
  • @Titanical _TimeoutException_ is the outcome of **failed** _expected-conditions_. Debug your code through `find_element_by_*` in-conjunction with `time.sleep()`. If you are able to locate the element, update the question with the observations. – undetected Selenium Dec 28 '18 at 04:11
  • I took out "focused" from your suggestion using CSS_SELECTOR and it worked. The "focussed" qualifier seems dynamic and is added when I click on a box. – Titanical Jan 15 '19 at 18:15
0

I would suggest you to check if the element you trying to interact with is in iframe. To identify this you can: Right click on the element, If you find the option like 'This Frame' then it is an iframe; or you can just search in page source for iframe tag to identify.

you can refer to this question for further solution if indded your element is part of iframe: Select iframe using Python + Selenium

Tejas Jagtap
  • 11
  • 1
  • 3