当元素可单击时,Selenium WebDriverWait失败

发布于 2025-02-13 11:44:18 字数 1124 浏览 0 评论 0原文

我设置了一个WebDriverWait,以等待可单击的元素。它在其他项目中工作,除了此元素以外的所有内容,它都在此项目中起作用。

    def wait_for_element(self, id: str, wait) -> bool:
    if wait > 20:
        wait = 20
    try:
        return WebDriverWait(self.driver, timeout=wait).until(
            EC.element_to_be_clickable((By.CSS_SELECTOR, "[data-automation-id='" + id + "']")))
    except TimeoutException:
        debug_print("Element could not be found or is not clickable: " + id)
        return False

此功能在以下代码中使用,并添加了前四行进行调试:

    element = self.get_element(self.IDs['CHECKSELECT'] + '0')
    print(element.is_enabled())
    print(element.get_attribute('data-automation-id'))
    assert self.click_element(self.IDs['CHECKSELECT'] + '0')
    assert self.wait_for_element(self.IDs['CHECKSELECT'] + '0', 5)

以上代码打印以下内容:

True
opt-chk-select-0
('Element could not be found or is not clickable:opt-chk-select-0',)

我还设置了此设置以在拆卸时进行屏幕截图,并且屏幕截图显示了该元素已成功单击。我正在努力理解为什么该元素告诉我它是可单击的,数据自动化ID正是我所期望的,并且自动化可以成功单击它,而等待它可以单击, 之后已经单击,正在失败。有人有任何想法吗?我无法提供更多的信息,例如正在测试的网站。

I have a WebDriverWait set up to wait for an element to be clickable. It works in other projects and for everything except this element, it's working in this project.

    def wait_for_element(self, id: str, wait) -> bool:
    if wait > 20:
        wait = 20
    try:
        return WebDriverWait(self.driver, timeout=wait).until(
            EC.element_to_be_clickable((By.CSS_SELECTOR, "[data-automation-id='" + id + "']")))
    except TimeoutException:
        debug_print("Element could not be found or is not clickable: " + id)
        return False

This function is used in the following code, with the first four lines added for debugging:

    element = self.get_element(self.IDs['CHECKSELECT'] + '0')
    print(element.is_enabled())
    print(element.get_attribute('data-automation-id'))
    assert self.click_element(self.IDs['CHECKSELECT'] + '0')
    assert self.wait_for_element(self.IDs['CHECKSELECT'] + '0', 5)

The above code prints the following:

True
opt-chk-select-0
('Element could not be found or is not clickable:opt-chk-select-0',)

I also have this set up to take a screenshot on teardown, and the screenshot shows me that the element was clicked successfully. I'm struggling to understand why the element is telling me it is clickable, the data automation ID is exactly what I expect it to be, and the automation can successfully click it, yet waiting for it to be clickable, after it has already been clicked, is failing. Does anybody have any idea? I'm unable to provide more info than this, such as the website under test.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文