【发布时间】:2015-02-12 13:30:35
【问题描述】:
我是 selenium 的新手,我正在尝试从下拉列表中选择一个选项。以下是下拉菜单的 HTML:
<input type="text" ng-blur="getInventoryStatus()"
typeahead-on-select="onDeviceSelect($item)"
typeahead="device as device.name for device in deviceList| filter:$viewValue |orderBy:'name':false"
ng-model="deviceSearch" placeholder="SKU / Item Name" class="form-control
ng-pristine ng-valid" autocomplete="off" aria-autocomplete="list"
aria-expanded="false" aria-owns="typeahead-00F-1916">
WebElement 的xpath 是:
/html/body/div[3]/div[2]/div/div/div/div/div[2]/div/div[3]/div[2]/div[2]/div/div[3]/div[4]/div[3]/div[1]/div[1]/input
我尝试了几乎所有可以在互联网上找到的方法,但没有任何效果。
我尝试使用Select 类,包装了WebElement,但它抛出了NoSuchElement 的异常。
我试图丢失列表中的所有选项,但在这种情况下出现异常ui.UnexpectedTagNameException.Element 应该有标签Select 但它有input。我需要使用 xpath 作为 findelements 的标识符。
请帮帮我。
【问题讨论】:
-
这里没有 HTML。
-
我也遇到过这些问题,但现在不记得解决方案了。尝试使用 javascript
jQuery.click()选择选项。 -
选择不起作用。你能检查
findElement(By.xpath("//input[@placeholder='SKU / Item Name']"))是否返回一个元素吗? -
findElement(By.xpath(//.....)) 重新调整元素,因为我可以点击它。 @VivekSingh
标签: html selenium selenium-webdriver