Module17:Big basket--> Print all product names | Selenium Forum
M
Posted on 14/10/2016
In this particular screen, on page load 20 products are visible. when scroll to last product then another 20 products are visible which goes on continuing till 8th page.

[b:todh7w9h][u:todh7w9h]Xpath for first 20 products[/u:todh7w9h][/b:todh7w9h]

WebElement productlist = d.findElement(By.xpath("//div[@class='uiv2-shopping-list-right-column']"));

List<WebElement> firstpageproductnames=productlist.findElements(By.xpath("//div[@id='products-container']/div[@class='jscroll-inner']/div[@class='uiv2-shopping-lis-sku-cards']/ul[@class='uiv2-our-recommendations-list-box']/li[starts-with(@id,'product')]/div[@class='uiv2-list-box-img-title']/span[@class='uiv2-title-tool-tip']/a"));

Using while loop, i tried to print all product names with above xpath (as per your example on Printing facebook friends)
But each and everytime count is used to print only 20. Later identified that there is change in xpath for remaining products.

Another tag "div[@class='jscroll-added']" is included for remaining.

secondpageproductnames=productlist.findElements(By.xpath("//div[@id='products-container']/div[@class='jscroll-inner']/[b:todh7w9h][u:todh7w9h]div[@class='jscroll-added'][/u:todh7w9h][/b:todh7w9h]/div[@class='uiv2-shopping-lis-sku-cards']/ul[@class='uiv2-our-recommendations-list-box']/li[starts-with(@id,'product')]/div[@class='uiv2-list-box-img-title']/span[@class='uiv2-title-tool-tip']/a"));

i tried to print all product names with below logic. can you please suggest me whether this is correct way or it can be improved further.

[attachment=0:todh7w9h]Print all products_Bigbasket.png[/attachment:todh7w9h]

M
Replied on 15/10/2016

are you sure these xpaths working

[code:2oja6trs]//div[@id='products-container']/div[@class='jscroll-inner']/div[@class='uiv2-shopping-lis-sku-cards']/ul[@class='uiv2-our-recommendations-list-box']/li[starts-with(@id,'product')]/div[@class='uiv2-list-box-img-title']/span[@class='uiv2-title-tool-tip']/a[/code:2oja6trs]

couldn't you find smaller xpaths?


M
Replied on 16/10/2016

Yes, Xpaths in below screenshot are working


M
Replied on 17/10/2016

can you come on skype?