如何使用Java从SeleniumWebDriver中的不可见下拉元素中选择选项
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>
完全同意Ross Patterson的观点,但如果你仍然想尝试上述场景,这可能会奏效。。。
((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';");
相关文章:
- 根据select选项元素将表单重定向到不同的URL
- WebdriverIO waitForExist()选择元素's选定的选项
- 如果类不是一个选项,如何在使用 jQuery 时控制(避免)嵌套 html 元素的样式
- 向html选择元素添加选项
- 我如何为列出的选项卡元素编写一个Protractor测试,它会检查它是否's是否处于活动状态
- 选项卡式元素上的动画CSS转换
- 只有当Angular从资源对象检索数据时,才选择选项元素
- Angular 指令似乎没有使用元素传入的选项执行
- 使用docment.createElement向元素添加选项
- Angular始终选择选择元素中的第一个选项
- 选择不追加在动态添加的行上的元素选项
- 动态更新 JavaScript 和 PHP 中的选择元素选项
- 创建一个 html 页面,其选择元素选项相同
- 获取所有选定元素选项的文本
- 使用jquery.on()方法处理同一元素(选项标记)的两个脚本之间的冲突
- jQuery:保存已选择的select元素选项
- 禁用基于类的选择元素选项
- 在页面加载时设置select元素选项
- 禁用Firefox中弹出的选择元素选项
- 在Bootstrap元素选项中使用引号中的引号