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">

Webドライバーで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 に答える