【问题标题】:I am not able to select option value from drop down list .select tag not containing any id or class or name我无法从下拉列表中选择选项值。选择标签不包含任何 id 或类或名称
【发布时间】:2014-02-17 18:48:58
【问题描述】:

我无法从下拉列表中选择选项值。选择标签不包含任何 id 或类或名称。

 <select>
 <option title="Select" value="">Select</option>
 <option title="Packages" value="PK" maxCount="1" cgCount="0">Packages</option>
 </select>

【问题讨论】:

  • 它的父级呢?它有 id、类名或任何其他属性吗?

标签: selenium


【解决方案1】:

使用这个,我的作品:):

WebElement element = driver.findElement(By.xpath("//select"));
    Select dropdown = new Select(element);
    dropdown.selectByIndex(1); 

来源:Sumit Mittal Blog

【讨论】:

  • 你能告诉我,如何输入?
  • 使用:dropdown.selectByVisibleText("Packages");
【解决方案2】:

只需将您的 WebElement 包装到 Select Object 中,如下所示

Select dropdown = new Select(driver.findElement(By.id("identifier"))); 完成此操作后,您可以通过 3 种方式选择所需的值。考虑一个这样的 HTML 文件

<select id="designation">
<option value="MD">MD</option>
<option value="prog"> Programmer </option>
<option value="CEO"> CEO </option>
</select>

下面是下拉列表:)

现在要识别下拉菜单

1

Select dropdown = new Select(driver.findElement(By.id("designation")));

要选择它的选项说“程序员”,你可以这样做 ? 1

dropdown.selectByVisibleText("Programmer ");

或 ? 1

dropdown.selectByIndex(1);

或 ? 1

dropdown.selectByValue("prog");

dropdown.selectByVisibleText("Programmer");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-14
    • 2016-10-13
    • 2016-08-18
    • 1970-01-01
    • 2015-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多