How t get selenium to recognise a button and click it

Tags: , ,

How would I get selenium python to recognise this button in HTML?

ive tried this and other tags to get it

        print('button was clicked')

This is the button snippet code

<button class="cookie-monster__cta cookie-monster__cta--primary js-cookie-monster-accept">
<span class="glyphicon glyphicon-ok"></span>
Accept All Cookies


Your locator is wrong. The class is named cookie-monster__cta, not .cookie-monster. js-cookie-monster-accept seems to be unique class name. Use it for finding your element. Also, you should wait for elements before clicking them.

from import WebDriverWait
from import expected_conditions as EC
from import By

wait = WebDriverWait(driver, 20)
                (By.CSS_SELECTOR, "js-cookie-monster-accept")))
button = driver.find_element_by_css_selector("js-cookie-monster-accept")

If this locator is not unique, add classes one by one to both wait and find_element_by_css_selector, like this:


Source: stackoverflow