Mornon
Mornon

Reputation: 79

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

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?

Upvotes: 4

Views: 236

Answers (3)

Rado
Rado

Reputation: 66

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.

Upvotes: 1

Aayush Agrawal
Aayush Agrawal

Reputation: 1394

Bypass this by using javascript to carry out the click:

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

Upvotes: 0

0buz
0buz

Reputation: 3503

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()

Upvotes: 1

Related Questions