我有一个包含值的下拉列表,在尝试选择值时收到此错误消息(无法共享链接,因为它是隐藏的):
Element: [[[[ChromeDriver: chrome on WINDOWS (4aeb1bf64ec7a13956b6b0b2cf24d9ca)] -> xpath: //*[@id="Datatable_ReceiptListModel"]/tbody/tr[3]/td[10]/select]] -> xpath: .//option[normalize-space(.) = "Option 1"]]
该下拉列表的HTML为:
<select class="select-submotive inputs-table hide-in-partial" style="visibility: visible;">
<option value="">Seleccione...</option>
<option value="5">Option 1</option>
<option value="6">Option 2</option>
</select>
XPATH为:
//*[@id="Datatable_ReceiptListModel"]/tbody/tr[1]/td[10]/select
我这样做了:
Select dropdown736 = new Select(driver.findElement(By.xpath("//*[@id=\"Datatable_ReceiptListModel\"]/tbody/tr[3]/td[10]/select")));
dropdown736.selectByVisibleText("Option 1");
我做错什么了吗?
2条答案
按热度按时间nmpmafwu1#
试试看:
您也可以使用Xpath按文本单击元素,如下所示:
juud5qan2#
这段代码对我来说非常好用:
对于此html结构: