【发布时间】:2018-12-03 20:31:17
【问题描述】:
我正在尝试对搜索结果进行分页:Becoming Amazon search。我得到一个'NoSuchElementException'..'Unable to locate element: < insert xpath here >
这里是html:
<div id="pagn" class="pagnHy">
<span class="pagnLink">
<a href="/s/ref=sr_pg_2?rh=...">2</a>
</span>
</div>
这是我尝试过的 xpath:
driver.find_element_by_xpath('//*[@id="pagn" and @class="pagnLink" and text()="2"]')
driver.find_element_by_xpath('//div[@id="pagn" and @class="pagnLink" and text()="2"]')
driver.find_element_by_xpath("//*[@id='pagn' and @class='pagnLink' and text()[contains(.,'2')]]")
driver.find_element_by_xpath("//span[@class='pagnLink' and text()='2']")
driver.find_element_by_xpath("//div[@class='pagnLink' and text()='2']")
如果我只使用find_element_by_link_text(...),那么有时会选择错误的链接。例如,如果评论数等于我要查找的页码(在本例中为 2),那么它将选择具有 2 条评论的产品,而不是页码“2”。
【问题讨论】: