【发布时间】:2015-09-29 10:52:59
【问题描述】:
通常我像这样使用 selenium Select 对象:
val selectCode = new Select(driver.findElement(By.id("someID")))
selectCode.selectByValue("4")
我的问题是我在 html 代码中没有价值,这是按钮 html:
<button type="button" class="btn dropdown-toggle btn-default" data-toggle="dropdown" data-id="admin-select-page" title="Select..."><span class="filter-option pull-left">Select...</span> <span class="bs-caret"><span class="caret"></span></span></button>
这是我需要选择的值:
<li data-original-index="4" data-optgroup="2"><a tabindex="0" class="opt " style="" data-tokens="null"><span class="text">
Invoices
</span><span class="glyphicon glyphicon-ok check-mark"></span></a></li>
但正如你在上面看到的,我通常有 id 和 value 所以 By.id 或 By.value 会起作用...
在这种情况下如何选择它..?
谢谢!
【问题讨论】:
-
最好的方法是通过 xpath 或 cssSelector 进行选择。但是我不能给你 xpath 的例子,因为没有足够的 hmtl 代码给你正确的 xpath...