I'm trying to paginate through the results of this search: Becoming Amazon search. I get a 'NoSuchElementException'..'Unable to locate element: < insert xpath here >
Here is the html:
<div id="pagn" class="pagnHy">
<span class="pagnLink">
<a href="/s/ref=sr_pg_2?rh=...">2</a>
</span>
</div>
Here are the xpaths I've tried:
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']")
If I just use find_element_by_link_text(...) then sometimes the wrong link will be selected. For example, if the number of reviews is equal to the page number I'm looking for (in this case, 2), then it will select the product with 2 reviews, instead of the page number '2'.