如何在SeleniumWebDriver(java)中使用xpath从隐藏表中提取值
我想从的“from”下拉列表中提取值,然后将其与特定的搜索字符串进行比较,以确定下拉列表中的值中是否存在该字符串。但是我无法提取这些值,因为这些字段是隐藏的。这是一个自动完成的下拉列表 下拉列表的html部分如何在SeleniumWebDriver(java)中使用xpath从隐藏表中提取值,java,selenium,xpath,Java,Selenium,Xpath,我想从的“from”下拉列表中提取值,然后将其与特定的搜索字符串进行比较,以确定下拉列表中的值中是否存在该字符串。但是我无法提取这些值,因为这些字段是隐藏的。这是一个自动完成的下拉列表 下拉列表的html部分 <div class="container"> <div class="search_selector" style="display: none;"> <div class="col-xs-12"> <div class="city_se
<div class="container">
<div class="search_selector" style="display: none;">
<div class="col-xs-12">
<div class="city_sel_top">
<div class="top_cities_scroll" style="margin-top: -5px;">
<ul id="near_button" class="top_cities_list" style="width: 98%;">
<ul class="from_city_list top_cities_list" style="width: 98%; display: none;">
<li class="top_cities_heading text-right">Top Domestic Cities</li>
<li id="DEL|Y|New Delhi|India">
<a class="from_city_value1" href="javascript:void(0);">New Delhi, India (DEL)</a>
</li>
<li id="DEL|Y|New Delhi|India">
<a class="from_city_value1" href="javascript:void(0);">New Delhi, India (DEL)</a>
</li>
<li id="BOM|Y|Mumbai|India">
<a class="from_city_value2" href="javascript:void(0);">Mumbai, India (BOM)</a>
</li>
<li id="BLR|Y|Bangalore|India">
<a class="from_city_value3" href="javascript:void(0);">Bangalore, India (BLR)</a>
</li
WebDriver driver;
List<WebElement> li = driver.findElements( By.xpath("//div/div[2]/ul[2]/li/a"));
WebDriver;
List li=driver.findElements(By.xpath(“//div/div[2]/ul[2]/li/a”);
这给了我一个无此类元素的例外,因为ul[2]下的第一个li元素下没有“a”元素。我想从第二个li元素开始获取“a”元素。您的XPath太严格了!使用.tagName(“a”)
如果您只想要第一项的“a”,那么我认为SiKing的解决方案是最好的。但如果您必须使用xpath,那么我认为应该是:
//div/div/div/div[2]/ul[2]/li[2]/a