are you having trouble with comparison?
if yes then you can look into end with function
http://www.tutorialspoint.com/java/java_string_endswith.htm
Hi,
I am facing the problem during click on the "Add" button for put the items into Basket.
Also Qty. of [b:25vpclji]Total Name[/b:25vpclji] and [b:25vpclji]Total Buttons[/b:25vpclji] are also not same. I tried allot for xpath of both but not found any solution. So plz help.
[b:25vpclji]NOTE:- Screenshot and project is attached.[/b:25vpclji]
[b:25vpclji]Code [/b:25vpclji]:-
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
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.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class BigBasket_Excel {
public static void main(String[] args) throws InterruptedException
{
Xls_Reader xls = new Xls_Reader("D:\\bigbasket.xlsx");
int row = xls.getRowCount("Products");
List<String> productNameTobeAdded = new ArrayList<String>();
List<String> productQtyTobeAdded = new ArrayList<String>();
for (int i =2;i<=row; i++){
String ProductName = xls.getCellData("Products", "ProductName", i);
String ProductQty = xls.getCellData("Products", "Qty", i);
productNameTobeAdded.add(ProductName);
productQtyTobeAdded.add(ProductQty);
}
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.get("http://www.bigbasket.com/cl/fruits-vegetables/?nc=nb");
driver.findElement(By.xpath("//*[@id='skip_explore']")).click();
List<WebElement> allProducts = driver.findElements(By.xpath("//div[@class='uiv2-list-box-img-title']/span[2]/a"));
List<WebElement> allButtons = driver.findElements(By.xpath("//a[starts-with(@id,'p_')]"));
System.out.println("Total Name ---- > " + allProducts.size());
System.out.println("Total Buttons ---- > " + allButtons.size());
for (int i =0; i <allProducts.size();i++){
String test=allProducts.get(i).getText();
String[]VegetableName = new String[100];
if(test!=null && !test.isEmpty())
{
VegetableName =test.split("\n"); // Create String type Array to remove unwanted text like FRESHO\n
//System.out.println(VegetableName[1].toString()); // Will Print only product name which need to be added.
}
int incr=1;
if(productNameTobeAdded.contains(VegetableName[incr])){
//allButtons = driver.findElements(By.xpath("//a[starts-with(@id,'p_')]"));
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy((By.xpath("//a[starts-with(@id,'p_')]"))));
allButtons = driver.findElements(By.xpath("//a[starts-with(@id,'p_')]"));
allButtons.get(i).click(); [b:25vpclji]//------>>>> PROBLEM IS IN THIS LINE <<<<<<<<<------[/b:25vpclji]
allProducts = driver.findElements(By.xpath("//div[@class='uiv2-list-box-img-title']/span[2]/a"));
allButtons = driver.findElements(By.xpath("//a[starts-with(@id,'p_')]"));
}
incr++;
}
}
}
ERROR:- Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
Command duration or timeout: 20.10 seconds.
Is anybody do this exercise. Please help me i am stuck over here from last 2-3 days and not found any solution.
try this and tell me the result
driverWait.until(ExpectedConditions.presenceOfElementLocated(allButtons.get(i)));
Hi,
Please give me the solution of it.. i am waiting for this.
Waiting for your reply.
Hi Ashish,
I observed the HTML for the Products display onto the Website.
1.
Products are display into 4 different Panels in HTML. [b:d41qrvwf]Look into Screen Shot -1[/b:d41qrvwf]
2.
I search first 4 Products-Names on first Panel in HTML. i.e. [b:d41qrvwf]"Fresho Onion - Medium 1"[/b:d41qrvwf] , [b:d41qrvwf]"Fresho Potato"[/b:d41qrvwf] , "[b:d41qrvwf]Fresho Tomato Hybrid[/b:d41qrvwf]"
and "[b:d41qrvwf]Fresho Apple- Fuji [/b:d41qrvwf]". [b:d41qrvwf]Look into Screen Shot-2[/b:d41qrvwf]. In the HTML <a> tag comes under 3rd <div>.
3.
Now i want to search the Products into second Panel In HTML i.e. [b:d41qrvwf]"Fresho Ladies Finger"[/b:d41qrvwf] , "[b:d41qrvwf]Fresho Cauliflower (Medium)[/b:d41qrvwf]" , "[b:d41qrvwf]Fresho Carrot Local[/b:d41qrvwf]"
and "[b:d41qrvwf]Fresho Palak[/b:d41qrvwf]". Now <a> tag comes under 2nd <div>. [b:d41qrvwf]Look into Screen Shot - 3[/b:d41qrvwf]. <a> tag comes under 2nd <div>.
[b:d41qrvwf]Xpath of Products in 1st Panel [/b:d41qrvwf]:- .//li[starts-with(@id,'product_')]/div[3]/span[2]/a/span -----> Here Span comes under the 3rd div.
[b:d41qrvwf]
[b]Xpath of Products in 2nd Panel[/b:d41qrvwf]:- .//li[starts-with(@id,'product_')]/div[2]/span[2]/a/span -----> Here Span comes under the 2nd div.
[b:d41qrvwf]Observation [/b:d41qrvwf]:- There is issue in my Xpath so please look into this and guide me.
i have tried understanding your code but i'm unable to.
i request a meeting. so, i can better understand the code you wrote. send me a skype message on qtpselenium1
Hi Sam,
This is my code... U can try this...
package exercises;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.Test;
public class BigBasket {
WebDriver driver;
WebDriverWait wait;
@Test
public void Test1() throws InterruptedException {
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(60,TimeUnit.SECONDS);
//Step 1 : a) Go to http://bigbasket.com/
driver.get("http://www.bigbasket.com");
driver.findElement(By.xpath("//*[@id='skip_explore']")).click();
driver.findElement(By.xpath("//*[@id='basket_menu']/ul/li[1]/a")).click();
//Step 2:b) You have to add 5 different products in basket
List<WebElement> Product_Name_lst = driver.findElements(By.xpath("//div[@id='facet-products-wrapper']/div[2]/div/div/ul/li/div/span[2]/a"));
List<WebElement> Add_btn_lst = driver.findElements(By.xpath("//div[@id='facet-products-wrapper']/div[2]/div/div/ul/li/div/div[2]/div/a"));
List<WebElement> Quantity_lst = driver.findElements(By.xpath("//div[@id='facet-products-wrapper']/div[2]/div/div/ul/li/div/div[2]/div/div[3]/input[@type='text']"));
Excel_Supplier testData = new Excel_Supplier("C:\\Users\\admin\\workspace\\Module17\\bigBasketTestData.xlsx");
int rows = testData.getRowCount("Sheet1");
int columns = testData.getColumnCount("Sheet1");
System.out.println(rows);
System.out.println(columns);
List<String> User_Products = new ArrayList<>();
List<String> User_Qty = new ArrayList<>();
for(int i=2; i<=rows;i++)
{
User_Products.add(testData.getCellData("Sheet1", "ProductName", i));
User_Qty.add(testData.getCellData("Sheet1", "Quantity", i));
}
Actions act = new Actions(driver);
int count =0;
for(int j=0;j<Product_Name_lst.size();j++)
{
//System.out.println(Product_Name_lst.get(j).getText().replace("FRESHO", "").replace("\n", "").trim());
//String Compare_Text = Product_Name_lst.get(j).getText().replace("FRESHO", "");
for(int k=0;k<User_Products.size();k++)
{
if(User_Products.get(k).equals(Product_Name_lst.get(j).getText().replace("FRESHO", "").replace("\n", "").trim()))
{
act.moveToElement(Product_Name_lst.get(j)).build().perform();
Quantity_lst.get(j).clear();
String Text = User_Qty.get(k);
Quantity_lst.get(j).sendKeys(Text);
Thread.sleep(3000);
Add_btn_lst.get(j).click();
Thread.sleep(3000);
/*
System.out.println(User_Products.get(k));
System.out.println(User_Qty.get(k));
String Text = User_Qty.get(k);
System.out.println(Text);
*/
count++;
}
}
}
String cart_Items = driver.findElement(By.xpath("//span[@class='uiv2-num-basket-items']")).getText().replace("items", "").trim();
int verify_AddedItems = Integer.parseInt(cart_Items);
if(verify_AddedItems==count)
{
System.out.println(count+"- Product is Added Successfully!!!!");
}
WebElement cart = driver.findElement(By.xpath("//div[@class='uiv2-basket-items']"));
act.moveToElement(cart).build().perform();
Thread.sleep(3000);
driver.findElement(By.xpath("//a[@class='uiv2-checkout-button-small fltr view_basket_checkout']")).click();
// U Must login :
driver.findElement(By.xpath("//*[@id='uiv2-loginform']/div[2]/span/input")).sendKeys("jakay507@gmail.com");
driver.findElement(By.xpath("//*[@id='password']")).sendKeys("12345678");
driver.findElement(By.xpath("//*[@id='password']")).sendKeys(Keys.ENTER);
// verify the Sub total :
//List<WebElement> Quantity_list = driver.findElements(By.xpath("//div[@class='uiv2-yourbasketitems-gridlist']"
// + "/div/ul/li[4]/div/input"));
List<WebElement> Sub_total_Amont_list = driver.findElements(By.xpath("//span[@class='uiv2-subtotal-rate']/span[2]"));
String getFinal_Totals = driver.findElement(By.xpath("//div[@class='uiv2-subtotal-listblock']/b/span")).getText().replace("Rs.", "").trim();
Double Expected_Result = Double.parseDouble(getFinal_Totals);
Double sum =0.00;
for(int s_tot =0; s_tot<Sub_total_Amont_list.size();s_tot++)
{
String temp = Sub_total_Amont_list.get(s_tot).getText();
Double getEachsub= Double.parseDouble(temp);
sum = getEachsub+sum;
}
System.out.println(sum);
System.out.println(Expected_Result);
System.out.println("*************************************************************");
Assert.assertEquals(sum, Expected_Result);
System.out.println("ACTUAL RESULT IS EQUALS TO EXPECTED RESULT.");
System.out.println("*************************************************************");
}
}