Search code examples
pythonpython-3.xselenium-webdriverselenium-chromedriverfindelement

Unable to locate element using Selenium and Python


I'm trying to click on an accept cookies button while navigating a webpage using Selenium and Python.

Pic of cookie button

I've used inspect element to find the class name of the button, and then .click() in Python to click on it. It isn't a link, but if it were working the accept cookies pop-up would disappear, and it isn't.

HTML on website for the button

Instead, I'm getting this error:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".SubmitButton CookiePopup-button"}

Here is the code I am running:

cookie_button = driver.find_element("class name", "SubmitButton CookiePopup-button").click()

Thanks for your responses!


Solution

  • You may try this, see if it works

    cookie_button = driver.find_element(By.CSS_SELECTOR, "button.SubmitButton.CookiePopup-button").click()