【问题标题】:Selenium element not interactable with same idSelenium 元素不能与相同的 id 交互
【发布时间】:2022-01-07 05:52:28
【问题描述】:

我有一个像这样的基本页面类

public class BasePage{
    @FindBy(id = "select2-ccnl-container")
    protected WebElement ccnlSelect;

    public void clickSettingCcnl(){
        ccnlSelect.click();
    }
}

然后我创建了 2 个类 Page1Page2 都扩展了 BasePage。 这些是 2 个不同的页面,其中包含具有该 ID 的元素。当我在Page1 的测试中使用clickSettingCcnl() 时,一切正常。

但是Page2 上的同样的事情给了我org.openqa.selenium.ElementNotInteractableException: element not interactable

该元素在 Page1 上可见并可点击,因此在 Page2 上看起来也是如此。

【问题讨论】:

  • 可见!= 可点击
  • 没错,我已经更新了问题,两页上的项目完全相同,我不明白为什么他们有不同的行为
  • 您是否尝试过使用等待语句?
  • 是的,但我遇到了同样的异常
  • 公开WebElement ccnlSelect 或至少不受保护。

标签: java selenium testing css-selectors


【解决方案1】:

具有上述 id 的元素在另一个元素中,在 Page2 中它有一个动态添加的类,将其维度设置为 0,但我没有注意到它,因为父元素隐藏了这个转换。

通过删除该类,它返回到 > 0 的维度,因此可以被 Selenium 点击

【讨论】:

    猜你喜欢
    • 2022-07-01
    • 2019-03-18
    • 2020-03-25
    • 2021-08-02
    • 1970-01-01
    • 2017-10-03
    • 2020-03-08
    • 2021-12-16
    • 2021-04-22
    相关资源
    最近更新 更多