Selenium webdriver 如何选择SeleniumWebDriver中UL下的列表项

Selenium webdriver 如何选择SeleniumWebDriver中UL下的列表项,selenium-webdriver,Selenium Webdriver,下面是代码,我想选择第一个列表项i,e VAN <Div class="btn-group col-xs-12 noSidePad"> <button id="equipment-dropdown-btn" class="btn strip-radius btn-default dropdown-toggle col-xs-10 noSidePad" data-bind="html: selectedEquipment(), css: {'has-error' : $paren

下面是代码,我想选择第一个列表项i,e VAN

<Div class="btn-group col-xs-12 noSidePad">
<button id="equipment-dropdown-btn" class="btn strip-radius btn-default dropdown-toggle col-xs-10 noSidePad" data-bind="html: selectedEquipment(), css: {'has-error' : $parent.errorMessage() && selectedEquipment() == 'Select...'}" aria-expanded="false" data-toggle="dropdown" type="button">Flatbed</button>
<button class="btn btn-default equipt-toggle dropdown-toggle col-xs-2 noSidePad" aria-expanded="false" data-toggle="dropdown" type="button">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul id="equipmentType" class="dropdown-menu" data-bind="foreach: equipmentTypeResults" role="menu">
<li>
<a data-bind="text: EquipmentName, click: $.proxy($parent.populateEquipment, $parent), attr: { 'data-itemtype': ResultType.toLowerCase(), 'data-equipid': EquipmentTypeId }" href="javascript:void(0);" tabindex="-1" role="menuitem" data-itemtype="parent" data-equipid="6">**Van**</a>

平板
切换下拉列表
我被卡住了,我应该首先确定下拉字段,然后选择列表


非常感谢您在这个问题上提供的任何帮助或线索。

请先试用下面的Xpath

//ul[@id='equipmentType']/li/a[contains(.,'**Van**')]
如果有一个下拉列表具有此值,那么您需要首先单击该下拉列表

driver.findElement(YOUR Locator)).click();
List<WebElement> options = select.findElements(By.xpath("//ul[@id='equipmentType']/li"));
for (WebElement option : options) {
  if("**Van**".equals(option.getText()))
    option.click();
}
driver.findelelement(您的定位器))。单击();
List options=select.findElements(By.xpath(//ul[@id='equipmentType']/li));
用于(WebElement选项:选项){
如果(“**Van**”.equals(option.getText()))
选项。单击();
}

希望它能帮助您:)

您需要首先单击下拉按钮,通过Xpath可以获得该按钮来显示(或切换)选择列表

driver.findElement(按.Xpath(“.//按钮[///span[text()='Toggle Dropdown']])。单击()

然后

driver.findElement(By.Xpath(“.//ul[@id='equipmentType']]/[text()='**Van*'])。单击()

您可以使用其他值代替
**Van**
,使其更通用