【问题标题】:Selenium 2 - getting the selected option from drop down listSelenium 2 - 从下拉列表中获取选定的选项
【发布时间】:2012-09-29 08:03:23
【问题描述】:
<select class="selectCity">
<option></option>
<option value="Paris">Paris</option>
<option>New York</option>
<option>London</option>
</select>



    Select op1 = new Select(driver.findElement(By.xpath("(//*[@id='cityTable']//*[contains(@class,'selectCity')])")));
    List<WebElement> allSelectedOptions = op1.getAllSelectedOptions();
    WebElement firstSelectedOption = op1.getFirstSelectedOption();
    System.out.println("op1!!!!!"+firstSelectedOption.getText());

网页上用户选择的选项是伦敦。

把输出是op1!!!!!

如何在网页上找到已选中的选项?

提前致谢!

【问题讨论】:

  • 看起来它正在返回选定的选项。如果没有明确选择任何选项(即 html 是

标签: selenium selenium-webdriver


【解决方案1】:

Selenium.getSelectedLabel("//string locator");

以上代码有助于了解当前选择的女巫选项并从下拉列表中可见。

下拉框的字符串定位器可以是任何东西,例如:- name,id,xpath

EG:Selenium.getSelectedLabel("name=productIdxSel");

【讨论】:

    猜你喜欢
    • 2022-01-21
    • 2011-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-13
    相关资源
    最近更新 更多