Ami*_*dha 45 java selenium-webdriver
我是selenium的新手,目前正在研究selenium webdriver我想从下拉列表中选择一个值.id = periodId和选项很多,我试图选择过去52周.
这是Html标签:
<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>
Run Code Online (Sandbox Code Playgroud)
请建议我点击下拉列表的一些方法.
我尝试使用上面的示例行但是得到错误,例如Element当前不可见,因此可能无法与命令持续时间或超时交互:32毫秒下拉值是jquery multiselect小部件格式
Abh*_*ngh 104
只需将WebElement包装到Select Object中,如下所示
Select dropdown = new Select(driver.findElement(By.id("identifier")));
Run Code Online (Sandbox Code Playgroud)
完成此操作后,您可以通过3种方式选择所需的值.考虑像这样的HTML文件
<html>
<body>
<select id = "designation">
<option value = "MD">MD</option>
<option value = "prog"> Programmer </option>
<option value = "CEO"> CEO </option>
</option>
</select>
<body>
</html>
Run Code Online (Sandbox Code Playgroud)
现在要确定下拉列表了吗
Select dropdown = new Select(driver.findElement(By.id("designation")));
要选择其选项,请说"程序员",您可以这样做
dropdown.selectByVisibleText("Programmer ");
要么
dropdown.selectByIndex(1);
要么
dropdown.selectByValue("prog");
Run Code Online (Sandbox Code Playgroud)
小智 5
如果你想在一行中写下全部试试
new Select (driver.findElement(By.id("designation"))).selectByVisibleText("Programmer ");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
350417 次 |
| 最近记录: |