Module 17 exc5 bigbasket | Selenium Forum
M
Posted on 09/07/2016
hello sir ... in this exc. im getting different number product list and add button and so its not clicking on add button... plz help me

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;

public class BigBasket_Exc5{
static List<String> name2;
static List<String> name3=new ArrayList<String>();;

public static void main(String[] args) throws InterruptedException {


Xls_Reader datatable=new Xls_Reader("C:\\sunita_java\\Bigbasket.xlsx");
int r=datatable.getRowCount("Sheet1");
System.out.println("Total rows :"+r);


System.setProperty("webdriver.chrome.driver","C:\\sunita_java\\driverExe\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);


List<String> productToBeAdded=new ArrayList<String>();
Hashtable<String,String> QuantityToBeAdded=new Hashtable<String ,String>();
name2=new ArrayList<String>();

productToBeAdded=new ArrayList<String>();

for(int i=2;i<=r;i++){
String productName= datatable.getCellData("Sheet1", "ProductName", i);
String quantity= datatable.getCellData("Sheet1", "Quantity", i);
System.out.println(" product :"+productName +" Quantity: "+quantity);
productToBeAdded.add(productName);
QuantityToBeAdded.put(productName,quantity );
}
driver.get("http://www.bigbasket.com/cl/fruits-vegetables/?nc=nb");
driver.findElement(By.xpath("//*[@id='skip_explore']")).click();



List<WebElement> productlist = driver.findElements(By.xpath("//div[@class='uiv2-list-box-img-title']/span/a"));
System.out.println("product list:"+productlist.size());
List<WebElement> button = driver.findElements(By.xpath("//div[@class='uiv2-list-box-drop-rate-block']/div[2]/div/a"));
System.out.println("Add list:"+button.size());

int productcount=0;
for(int i =0;i<productlist.size();i++)
{
//prints name of all products on first page
// System.out.println(driver.findElements(By.xpath("//div[@class='uiv2-list-box-img-title']/span/a")).get(i).getText());
name2.add(driver.findElements(By.xpath("//div[@class='uiv2-list-box-img-title']/span/a")).get(i).getText());

if( productToBeAdded.contains(productlist.get(i).getText()))
{
System.out.println(" found product: "+ productlist.get(i).getText());

button.get(i).click();

// validate basket count
String count=driver.findElement(By.xpath("//span[@class='uiv2-num-basket-items']")).getText();
System.out.println("product count :"+ count);
Assert.assertEquals(count,String.valueOf(productcount+1));
productlist=driver.findElements(By.xpath("//div[@class='uiv2-list-box-img-title']/span/a")) ;

button =driver.findElements(By.xpath("//div[@class='uiv2-list-box-drop-rate-block']/div[2]/div/a")) ;
productcount++;


}

}

/* name2.removeAll(Arrays.asList("", null));
System.out.println(name2);

for(int j=0;j<name2.size();j++){
//System.out.println("****"+name2.get(j));
name3.add(name2.get(j).split("\n")[1]);
}
System.out.println("***"+name3);*/


}
}

l

M
Replied on 09/07/2016

[quote:2cae2cst]hello sir ... in this exc. im getting different number product list and add button and so its not clicking on add button... plz help me
[/quote:2cae2cst]

what is in the xlsx file?

please try to be clearer in your question. instead of posting your code. send screen shots of if you're getting an error/exception.


M
Replied on 09/07/2016

this is out of program... its not adding product in basket dont no where going wrong


Total rows :6
Starting ChromeDriver 2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4) on port 40269
Only local connections are allowed.
log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
product :FRESHO Onion - Medium Quantity: 1
product :FRESHO Palak Quantity: 2
product :FRESHO Tomato Local - Grade A Quantity: 1
product :FRESHO Cucumber Quantity: 2
product :FRESHO Water Melon Kiran Quantity: 2
product list:63
Add Button list:68






this is xlsx file

Responsive image

M
Replied on 11/07/2016

leave this exercise for now it has changed slightly a lot of users are getting the same problem.