【问题标题】:Selenium + Python + Unittest:Error message when executing Test "Other element would receive the click"Selenium + Python + Unittest:执行测试时出现错误消息“其他元素会收到点击”
【发布时间】:2020-06-08 07:53:51
【问题描述】:

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

您知道如何避免这种情况吗?

【问题讨论】:

  • 看起来像是一个警告,告诉用户他们关闭了 cookie。您可能应该先关闭它。 (有关闭按钮吗?)

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


【解决方案1】:

还值得考虑可能在主页上注入元素的其他脚本。鉴于错误的性质,这看起来很像那些会强制用户发出警报的 GDPR 合规插件之一。最好的选择是像 Aayush 提到的那样忽略它,然后继续你的脚本。

【讨论】:

    【解决方案2】:

    通过使用javascript执行点击绕过这个:

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

    【讨论】:

      【解决方案3】:

      此错误的一个常见实例是元素在页面上不可见,例如,您可能需要滚动才能到达该元素。 如果是这种情况,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()
      

      【讨论】:

        猜你喜欢
        • 2016-06-08
        • 2021-10-08
        • 1970-01-01
        • 2018-03-16
        • 2017-04-16
        • 2021-04-17
        • 2023-03-19
        • 2022-01-01
        • 1970-01-01
        相关资源
        最近更新 更多