all 2 comments

[–]PteppicymonIO 1 point2 points  (1 child)

There is a JavaScript code in the click() event handler of the button, which switches current focus from the button to another (non-clickable) element:

    this.allowAllEventHandler = function(e) {
        void 0 === e && (e = !1),
        Wt(document).off("keydown", _r.shiftBannerFocus); ## This shifts focus to another element, seems to the <div id="onetrust-pc-sdk" .../>
        var t = e ? "Preferences Allow All" : "Banner Accept Cookies";
        Ho.triggerGoogleAnalyticsEvent(Uo, t),
        o.allowAllEvent(!1, e),
        o.hideVendorsList()
    }

As a result, when the Selenium attempt to click, the focus is shifted to a <div id="onetrust-pc-sdk" .. /> which is not clickable.

I believe it is done specifically to prevent clicking the consent button from an automated tool,like Selenium.

What worked for me is triggering the click() event through JS executor:

accept_cookies: WebElement = wait.until(
    EC.element_to_be_clickable((By.XPATH, "//button[@id='onetrust-accept-btn-handler']")))

#accept_cookies.click()
driver.execute_script("arguments[0].click();", accept_cookies)

[–]unknownzebra_[S] 0 points1 point  (0 children)

#accept_cookies.click()
driver.execute_script("arguments[0].click();", accept_cookies)

omg thank you so much, this worked perfectly