Selenium, Get Elements By Xpath - Only Grab Last 60 Elements On Page
I'm having a little trouble working out how I can specify the last 60 elements on a page posts = driver.find_elements_by_xpath('''(//div[@class='hotProductDetails'])''') for post i
Solution 1:
If you are getting a invalid XPATH selector then something is wrong. There was extra ")" at the end. Below works for me
page = 2
xpath_selector = "(//div[@class='hotProductDetails'])[position() > {} and position() <= {}]".format ((page -1 ) * 50, page * 50)
Also if you want something like last 60 elements then you can even use below
xpath_selector = "(//div[@class='hotProductDetails'])[position() > last() - 60]"
Solution 2:
If the load more is taking elements and appending to the div contents which were initially loaded for the page, why not just keep track of the start and end points for the data?
For instance, if 1 - 10 is loaded by default, if I click "load more" than the div now holds 20 elements but I know I should only be concerned with 11 - 20 etc...? This is typically how I've solved this problem in the past.
Post a Comment for "Selenium, Get Elements By Xpath - Only Grab Last 60 Elements On Page"