How to select dropdown option from span in selenium webdriver

被刻印的时光 ゝ 提交于 2021-01-29 08:31:51

问题


Below is HTML code of the dropdown

<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>

By clicking the span dropdown will display. Dropdown values are inside li

How to select the options mentioned in the li. we have only span ID.


回答1:


Resolved this by using the following.

code snippet:

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


来源:https://stackoverflow.com/questions/55586742/how-to-select-dropdown-option-from-span-in-selenium-webdriver

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!