python - Selenium +Python+单元测试:Error message when executing Test "Other element would receive the click"

标签 python python-3.x selenium selenium-webdriver python-unittest

详细信息: 在我当前的项目中,我正在 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/

相关文章:

python - 我收到消息 : "Bad import syntax:" when I try to import a python function inside my gnuradio flowgraph

python - 带有 PyGObject 自省(introspection) Gtk+ 3 的 GenericTreeModel?

python - 适当的类和属性结构

python-3.x - 如何在 Tornado 上获取favicon.ico工作

selenium - "The app must be signed with a development identity"是什么意思?

javascript - 使用 selenium 进行 headless javascript 下载

Python 3.4 Selenium 处理 chromedriver 异常

Python 列表语法帮助

python - 如何在AWS EC2上安装Chromadb?

python - 在 Python 中查找并替换(可能)嵌套列表中的元素?