Selenium + Python + Unittest:Error message when executing Test "Other element would receive the click"

Viewed 188

Details: In my current project I am writing test cases about Python and Selenium within Magento. In doing so I request a slide surface (button).

Request:

def test_pagebuilder_slide_button_pagebuilder_button_primary(self):
        driver = self.driver
        driver.get("my_webseite.de")
        time.sleep(15)
        try: driver.find_element_by_id("slick-slide-control01").click()
        except AssertionError as e: self.verificationErrors.append(str(e)) 
        time.sleep(15)

Now I get the message that the test works because another area would prevent this. And this although I directly after the ID search and this is available.As first aid I had also taken a break, maybe that's why?

Error message:

selenium.common.exceptions.WebDriverException: Message: unknown error: Element <button type="button" role="tab" id="slick-slide-control01" aria-controls="slick-slide01" aria-label="... of 2" tabindex="-1">2</button> is not clickable at point (517, 612). Other element would
receive the click: <div role="alertdialog" tabindex="-1" class="message global cookie" id="notice-cookie-block" style="">...</div>

Do you have any idea how I can avoid this?

3 Answers

One common instance for this error is when the element is not visible on the page, as in you might, for example, need to scroll to reach that element. If that's the case ActionChains should do the trick:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains

WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, "slick-slide-control01")))
ActionChains(driver).move_to_element(driver.find_element_by_id("slick-slide-control01")).click().perform()

It is also worth considering other scripts that might inject elements on the main page. Given the nature of the error, this look rather like one of those GDPR compliancy plugins that would force the alert on user. The best option is to dismiss it like Aayush mentioned and then go on with your script.

Bypass this by using javascript to carry out the click:

browser.execute_script(document.getElementById("slick-slide-control01").click())
Related