English 中文(简体)
webdriver - 从下拉列表中选择国家而不使用 xpath
原标题:webdriver - selecting country from drop down list without using xpath
<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 或 csselector 从下调列表中选择联合王国?

谢谢!

最佳回答

怎么样

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有什么不对吗?

问题回答

暂无回答




相关问题
web scrape all items in a page with selenium

I am trying to bring all items in the webpage-for instance I would like to bring the first "Hillebrand Boudewynsz. van der Aa (1661 - 1717)" and then all the other 49 in the page MY code is ...

WARNING: Unable to find version of CDP to use for version 114

WARNING: Unable to find version of CDP to use for . You may need to include a dependency on a specific version of the CDP using something similar to org.seleniumhq.selenium:selenium-devtools-v86:4.6.0 ...

How to use multiple CSS locators as a selenium locator?

I m trying to hit a link in a table-row that contains multiple links. This pattern is used throughout the table. This works: browser.wait_for(:element => "css=tr:nth-child(1) li:nth-child(2) >...

Getting Selenium to login via .htaccess popup

I am using WebDriver (Selenium2) with Java on linux. I am using WebDriver to auto fill form and submit it. I am facing problem with htaccess sites i.e., I am not able to access htaccess site through ...

热门标签