【问题标题】:Select from dropdown in Selenium从 Selenium 的下拉列表中选择
【发布时间】: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


【解决方案1】:

如果下拉元素是可编辑字段,则此方法有效:

driver.findElement("dropdown rlement").sendKeys("your value");

【讨论】:

  • 谢谢。这工作正常。发送您所需的值,所需的值显示在下拉列表中。您现在只需单击下拉菜单中的选项。非常感谢:)
猜你喜欢
  • 2022-10-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-08
  • 2015-03-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多