Selenium 元素不能与相同的 id 交互

Selenium element not interactable with same id

我有一个像这样的基础页面class

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

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

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

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

该元素在 Page1 上可见且可点击,因此在 Page2 上显示。

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

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