如何点击<选项> WebDriver的元素? [英] How to click an <option> element with WebDriver?

查看:182
本文介绍了如何点击<选项> WebDriver的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一段UI代码

<select id="order_unit_line_rate_806782_is_addenda_enabled" class="selects_for_487886" onchange="select_addendum(806782, this);dateShowMemory(this.options[this.selectedIndex].value, '806782');" uniqueattr="Dynamic Site Accelerator / Dynamic Site Accelerator / Additional Usage Commitment / drop down" name="order_unit_line_rate[806782][is_addenda_enabled]">
     <option value="0" uniqueattr="Dynamic Site Accelerator / Dynamic Site Accelerator / Additional Usage Commitment / Fee">                     Fee                   </option>
     <option value="1" uniqueattr="Dynamic Site Accelerator / Dynamic Site Accelerator / Additional Usage Commitment / See Attached Addendum">                     See Attached Addendum                   </option>
</select>

其中< option> 标签是嵌套在< select> 标记内。我需要在第二个< option> 元素上点击(),这是下拉列表中的一个项目。当我尝试使用id / uniqueattr在< select> 标签上 click()时,可以点击下拉列表。

where the <option> tags are nested inside the <select> tag. I need to click() on the second <option> element which is an item in the dropdown list. The dropdown is clickable when i try to click() on the <select> tag using id / uniqueattr.

如何遍历嵌套在< select> <下的< option> 标签/ code>然后点击右边的项目?

How do I traverse the <option> tags nested under <select> and click on the right item?

推荐答案

这将选择值为1的选项选择ID为order_unit_line_rate_806782_is_addenda_enabled。

This will select the option with value "1" in the select with id "order_unit_line_rate_806782_is_addenda_enabled".

Select select = (Select)webdriver.findElement(By.id("your id here"));
select.selectByValue("1");

您也可以按索引或文字选择; 查看文档

You can also select by index or text; see the docs.

这篇关于如何点击&lt;选项&gt; WebDriver的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆