0
<a id="SIU2_country" class="button combobox-button country" onclick="event.cancelBubble = true; if (event.stopPropagation) { event.stopPropagation(); }" tabindex="9" style="cursor: auto;">
<span id="SIU2_country_span">&nbsp;</span>
<div class="combobox-menu" style="width: 298px; max-height: 212px; display: block;">
<div class="combobox-menu-item">
<span>United States</span>
</div>
<div class="combobox-menu-item">
<span>United Kingdom</span>
</div>
<div class="combobox-menu-item">

尽量避免在 webdriver 中使用 xpath:

(By.xpath("//a[@id='SIU2_country']/div/div/span[contains(text(),'United Kingdom')]"));

如何使用 id 或 cssselector 从下拉列表中选择英国?

谢谢!

4

1 回答 1

0

怎么样

List<WebElement> menuItemsList = driver.findElement(By.id("SIU2_country")).findElements(By.className("combobox-menu-item"));
WebElement menuItem = menuItemsList.get(1).findElement(By.tagName("span"));

不过这有点难看……请问在这里使用 xpath 有什么问题吗?

于 2012-05-23T10:46:45.700 回答