我想在我的 Selenium 测试的下拉列表中找到一个元素。我使用 firebug 查找 xpath,但我的 Selenium 代码找不到 xpath。我在下面的 html 代码中寻找选项值 2:
<div id="accountList_gbselect" class="gb-select text-luc3" style="">
<a class="text-luc3" href="#">Konto: xxxxxx 0 kr</a>
<select id="accountList" style="width: 300px; display: none;" onchange="submit();" size="1" name="accountList">
<option value="1xxxxx" selected="selected">Konto: 1xxxxxx 0 kr</option>
<option value="1xxxxx">Testname: 1xxxxx 6 771 kr</option>
<option value="5xxxxx">Konto: 5xxxxx 500 kr</option>
<div class="list">
</div>
在我的 Selenium 代码中,我使用了 findElement,并尝试了 xpath 和 cssSelector。但不能让它工作。这就是我认为我应该编写以在下拉列表中查找元素的方式:
driver.findElement(By.xpath(".//*[@id='accountList']/option[2]")).click();