繁体   English   中英

如何使用Java从Selenium WebDriver中的不可见下拉元素中选择选项

[英]How to select option from invisible drop-down element in Selenium WebDriver using Java

请任何人帮助我如何在Selenium WebDriver中找到隐形元素。 我想从下拉列表中选择一个选项,我的目标是通过ID查找元素。

但是在HTML标记中,元素不可见以选择该选项。 我验证了很多问题,因为他们提到使用JavascriptExceutor。

任何人都可以帮我html标签的java脚本:

<select id="periodId" name="period" style="display: none;">
<option value="l4w">Last 4 Weeks</option>
<option value="l52w">Last 52 Weeks</option>
<option value="daterange">Date Range</option>
<option value="weekrange">Week Range</option>
<option selected="" value="monthrange">Month Range</option>
<option value="yeartodate">Year To Date</option>
</select>

完全同意罗斯帕特森,但如果你仍想尝试上述场景,这可能会奏效......

((JavascriptExecutor)driver).executeScript("$('select#periodId').click();");
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("document.getElementById('periodId').style.display='inline';");
Select select = new Select(driver.findElement(By.id("periodId")));
select.selectByVisibleText("Last 4 Weeks");
executor.executeScript("document.getElementById('periodId').style.display='none';");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM