目前正在研究 selenium webdriver。我有很多下拉菜单,例如可视化、周期、类型等。下拉菜单中有很多选项。我想从下拉列表中选择一个选项,我的目标是通过 ID 查找元素。
但在 HTML 标记中,该元素不可见,无法选择该选项。我验证了很多问题,因为他们提到使用 javascript 执行器。
谁能帮助我 html 标签的 javascript:
<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>
您可以尝试使用以下脚本使元素可见:document.getElementById('periodId').style.display='block';
在 java 代码中,可以使用以下代码执行该脚本:
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("document.getElementById('periodId').style.display='block';");
如果您只想在下拉列表中选择一个选项,您可以使用以下 java 代码:
Select select = new Select(driver.findElement(By.id("periodId")));
select.deselectAll();
select.selectByVisibleText("Last 4 Weeks");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)