Selenium + Python + Unittest:Error 执行测试时的消息 "Other element would receive the click"
Selenium + Python + Unittest:Error message when executing Test "Other element would receive the click"
详情:
在我当前的项目中,我正在 Magento 中编写关于 Python 和 Selenium 的测试用例。在这样做时,我请求一个滑动表面(按钮)。
要求:
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)
现在我收到消息说测试有效,因为另一个区域会阻止它。还有这个虽然我直接搜完ID,这个是available.As急救我也休息了,可能是这个原因吧?
错误信息:
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>
你知道我该如何避免这种情况吗?
此错误的一个常见实例是元素在页面上不可见,例如,您可能需要滚动才能到达该元素。
如果是这样的话 ActionChains
应该可以解决问题:
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()
通过使用 javascript 执行点击来绕过这个:
browser.execute_script(document.getElementById("slick-slide-control01").click())
还值得考虑可能在主页上注入元素的其他脚本。鉴于错误的性质,这看起来很像那些会强制向用户发出警报的 GDPR 合规性插件之一。最好的选择是像 Aayush 提到的那样将其关闭,然后继续您的脚本。
详情: 在我当前的项目中,我正在 Magento 中编写关于 Python 和 Selenium 的测试用例。在这样做时,我请求一个滑动表面(按钮)。
要求:
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)
现在我收到消息说测试有效,因为另一个区域会阻止它。还有这个虽然我直接搜完ID,这个是available.As急救我也休息了,可能是这个原因吧?
错误信息:
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>
你知道我该如何避免这种情况吗?
此错误的一个常见实例是元素在页面上不可见,例如,您可能需要滚动才能到达该元素。
如果是这样的话 ActionChains
应该可以解决问题:
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()
通过使用 javascript 执行点击来绕过这个:
browser.execute_script(document.getElementById("slick-slide-control01").click())
还值得考虑可能在主页上注入元素的其他脚本。鉴于错误的性质,这看起来很像那些会强制向用户发出警报的 GDPR 合规性插件之一。最好的选择是像 Aayush 提到的那样将其关闭,然后继续您的脚本。