【问题标题】:How to select dropdown option from span in selenium webdriver如何从 selenium webdriver 中的 span 中选择下拉选项
【发布时间】:2019-04-09 06:53:42
【问题描述】:

下面是下拉菜单的 HTML 代码

<div class="comboBox" id="ATFType-main" nativeid="ATFType" iseditabletablecombo="false" style="left: 165px; top: 105px; width: 156px;">
    <a tabindex="75" data-tab="75" style="outline: medium none;" id="ATFType-box" class="comboBox_box" href="#">
        <span class="comboBox_inputs  comboBox-mandatory-input " id="ATFType-input" title="" aria-required="true" style="width: 140px;"></span>
        <span class="comboBox_buttons  comboBox-mandatory-btn " aria-haspopup="true" aria-owns="ATFType-lists" id="ATFType-button" tabindex="-1"></span>
    </a>
    <div class="comboBox_divs comboBox_corner-all" id="ATFType-div" style="height: 36.4px; width: 158px; overflow: hidden; display: none;">
        <ul class="comboBox_list  comboBox-mandatory " aria-hidden="true" aria-labelledby="ATFType-button" role="listbox" id="ATFType-lists" stylecomputed="true">
        <li data-value="" data-index="0" class="comboBox_lielements comboBox_active"></li>
        <li data-value="ATFR" data-index="1" class="comboBox_lielements">Account Transfer</li> 
        </ul>
    </div>
</div>

点击 span 下拉菜单将会显示。下拉值在 li

如何选择li中提到的选项。我们只有 span ID。

【问题讨论】:

  • 你可以添加
  • 标签,当你点击 span
  • 这个页面可以在外面访问吗,如果可以请分享链接
  • 网站无法在外部访问。在下面发布解决方案
  • 标签: selenium


    【解决方案1】:

    使用以下方法解决了这个问题。

    代码sn-p:

    {
    webElementName.click();
    String xpath="//*[@id='"+webElementId+"']//following::li[contains(text(),'"+FieldValue+"')]";
    driver.findElement(By.xpath(xpath)).click();
    }
    

    【讨论】:

      猜你喜欢
      相关资源
      最近更新 更多
      热门标签