有没有办法从下拉列表中选择一个选项,而不是在Selenium中使用“选择”类?

时间:2017-12-04 05:36:54

标签: java selenium-webdriver

除了在Selenium中使用“选择”类之外,有没有办法从下拉列表中选择一个选项?

1 个答案:

答案 0 :(得分:1)

是。另一种方法是,单击下拉菜单,然后使用单击方法从下拉列表中选择选项,如下所示:

WebElement ele = driver.findElement(By.xpath("<Xpath of dropdown element>"));     // To find the dropdown web element
List<WebElement> options = driver.findElements(By.xpath("<Xpath of dropdown Options"));    // To find the dropdown options
ele.click();      // To click on the dropdown element
options.get(<index>).click();      //To click on the option..