获取错误:org.openqa.selenium.ElementNotVisibleException:元素当前不可见,因此可能无法与之交互
public analyticsLandingPage verifyReportingProfile() throwsInterruptedException{
Select select = new Select(driver.findElement(By.className("select2-choice")));
select.selectByVisibleText("Arria");
return PageFactory.initElements(driver, analyticsLandingPage.class);
}
这是我的HTML页面:
<div id="s2id_reporting_profile_id" class="select2-container select2-allowclear reporting_profile select2-container-active"
style="width: 50%;">
<a class="select2-choice" tabindex="-1" href="javascript:void(0)">
<span id="select2-chosen-7" class="select2-chosen">AdOps Reporting Profile</span>
<abbr class="select2-search-choice-close"/>
我怎样才能让它工作?我需要它点击下拉列表并选择元素。谢谢
通常这是因为在Selenium注册下拉列表之前,您必须单击前端的按钮。很多时候,这是由javascript调用引起的。您是否尝试过单击div:
id="s2id_reporting_profile_id"
然后单击select2选项?
也可能是这样的:
select.selectByVisibleText("Arria");
单击该元素后该元素上是否有文本可见?或者当单击选择时,是否会从href="javascript: ull(0)"
中显示另一个元素?如果是这种情况,您需要在Selenium中单击它。
如果这没有帮助,你的问题很模糊,也许你可以编辑它,让它更有意义?帮助我们帮助你解决问题!