【发布时间】:2017-03-23 20:46:12
【问题描述】:
HTML 代码
<div class="filterInfoContainer">
<div class="result-header-right">
<div class="show-soldout">
<label for="soldout-switch">Display sold out products</label>
<label class="switch xs">
<input type="checkbox" name="soldout-switch" id="soldout-switch">
<div class="switch-slider"></div>
</label>
</div>
<div class="sort-by">Sorted by:
<select id="sortByDropdown">
<option value="popularity">Popularity</option>
<option value="price">Lowest price</option>
<option value="discount">Highest discount</option>
<option value="year">Latest release</option>
</select>
</div>
</div>
Showing 323 products
<div class="clearfix"></div>
</div>
我尝试过的 Xpath
.//*[@id='filterInfo']/div
.//*[@id='filterInfo']/div/text()
我想获取文本显示 323 个产品,但我的 xpath 没有返回我。由于此文本没有特定的 div,我很难得到它。
我尝试过的 Selenium 代码
driver.findElement(By.xpath(".//*[@id='filterInfo']/div"));
driver.findElement(By.xpath(".//*[@id='filterInfo']/div/text()"));
获取异常:无效的选择器
【问题讨论】:
-
是否有可能通过更改代码将“显示 323 个产品”移动到标记中?@Fey - 不可能更改代码:(
标签: java xpath selenium-webdriver