[quote:1wllbjgb]But unable to verify the product and quantity in the basket with the excel.
[/quote:1wllbjgb]
can you get data from the website?
Yes, I am able to get the product names and the quantity from the site. The below part (before the function definition addToBasket()) prints the quantity and products in the Cart:
for(int i=0;i<quantity_list.size();i++){
String full_name = part1_list.get(i).getText().trim() + " " + part2_list.get(i).getText().trim();
System.out.print(full_name);
String quant_indiv = quantity_list.get(i).getAttribute("value");
System.out.println(" ------- "+quant_indiv);
what are you trying to do here.
String full_name = [color=#FF0000:aa8mmnrq]part1_list.get(i).getText().trim() + " " + part2_list.get(i).getText().trim();
[/color:aa8mmnrq]
The product Name added to the Cart consists of two <a> tags
FRESHO
Potato
So, i have separately derived the two <a> tags into part1 and part2. I am then combining them to get the full name similar to the excel.
[attachment=0:1r11cubb]Screenshot of Basket.jpg[/attachment:1r11cubb]
There is a new "Offer" div which couldn't recognize the products on the page. I have changed the xpath of the searchResults to be more precise. Please update ONLY this line in the code (in addToBasket function). I am able to add items to the cart now.
List<WebElement> searchResults = driver.findElements(By.xpath("//div[@class='uiv2-list-box-img-title']/span/a"));
I am not getting any error. I tried again Now. I was able to successfully add the products to basket and also view them in cart.
The line highlighted is just clicking on the Search button after entering the product name (from excel). There is no change in the xpath of the button.
Please try again and let me know in case if you are still facing issues.
I have pinged on gmail and waiting for reply. In the meantime, I am attaching the output console that I got today morning.
If you are still facing issues, could you please help with the logic on how we can compare excel data (2 columns) with the Basket page (after getting the item names).
I will try the code and send for your review.
[attachment=0:1zbto4w7]BigBasket Console Output.jpg[/attachment:1zbto4w7]
The query is solved after talking with Ashish. I was successfully able to compare the excel values with the Cart.
Thanks Ashish for guiding on the logic.
(Might not be an effective one, but still got the task done. Look forward to optimize after going through Framework videos)
Below code after the for loop of //Printing Cart Products and their Quantity
//Verifying against Excel
for(int rNum=2;rNum<=rows;rNum++){
String prod = xls.getCellData("Sheet1",0,rNum);
String quant = xls.getCellData("Sheet1",1,rNum);
for(int i=0;i<quantity_list.size();i++){
String full_name = part1_list.get(i).getText().trim() + " " + part2_list.get(i).getText().trim();
if(full_name.toLowerCase().contains(prod.toLowerCase())){
if(quantity_list.get(i).getAttribute("value").equals(quant)){
System.out.println("Product "+prod+" is present in Cart (displayed as ["+full_name+"]) with Quantity "+quant+" which is expected");
break;
}
}
}
}