详细信息: 在我当前的项目中,我正在 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搜索之后就可以使用这个。作为急救我也休息了一下,也许这就是原因?
错误消息:
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()
关于python - Selenium +Python+单元测试:Error message when executing Test "Other element would receive the click",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60380083/