Module 17 session 5, problem placing first item in Basket | Selenium Forum
M
Posted on 14/02/2016
The html page is:
https://uk.webuy.com/search/index.php?stext=*&section=&catid=956
and I am trying to press "I want to buy this item" button for the following 3 products which are in top of the page,
as item #0, item #1 and item #2:

Sims 3 - Offline (SN) (Not EA Origins)
Sims 2, The (SN) *4 DISC*
Sims 2, University *2 Disc* (SN)
and I have
List<WebElement> allNames = driver.findElements(By.xpath("//div[@class='searchRecord']/div[2]/h1/a"));
List<WebElement> allButtons = driver.findElements(By.xpath("//div[@class='action']/div/a[2]/div/span"));
allButtons.get(0).click();
allButtons.get(1).click();
allButtons.get(2).click();

somehow only item #1 & #2 shows up in the basket. Item #0 does not show up.
so, what I did was placed 2 more allButtons.get(0).click(); in there, and then I got product #0 showed up in the basket.
I did try the wait statement as in:
WebDriverWait wait = new WebDriverWait(driver, 60);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("buyBasketCount")));

and it did not make a difference.
Somehow product #0 never shows up in the basket. Am I missing something?
I am trying to see these 3 products in the view basket, and continuously one of them is missing from basket, How Do I resolve this issue?

Thank you
Fariba

M
Replied on 14/02/2016

I also tried the following in my code & it did not work:

WebDriverWait wait = new WebDriverWait(driver,120);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("html/body/div[5]/div[1]/div[3]/div[5]/div[1]/div[1]/div[3]/div/a[2]/div/span")));


M
Replied on 14/02/2016

This is the short version of the program, that displays the very first product never makes it to the basket. Please let me know what the problem is.

public class ZWeBuy {


static WebDriver driver;

@Test
public void testProductPurchaseProcess() {
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("https://uk.webuy.com/search/index.php?stext=*&section=&catid=956");
closePopupIfPresent();

//xpath for all product names in this page
List<WebElement> allNames = driver.findElements(By.xpath("//div[@class='searchRecord']/div[2]/h1/a"));
List<WebElement> allButtons = driver.findElements(By.xpath("//div[@class='action']/div/a[2]/div/span"));

System.out.println("Total names = "+ allNames.size());
System.out.println("Total buttons = "+ allButtons.size());
System.out.println("I= " + 0 + " PRDCT: --- " +allNames.get(0).getText());
allButtons.get(0).click();
WebDriverWait wait = new WebDriverWait(driver,120);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("html/body/div[5]/div[1]/div[3]/div[5]/div[1]/div[1]/div[3]/div/a[2]/div/span")));
System.out.println("I= " + 1 + " PRDCT: --- " +allNames.get(1).getText());
allButtons.get(1).click();
System.out.println("I= " + 2 + " PRDCT: --- " +allNames.get(2).getText());
allButtons.get(2).click();


}

public static void closePopupIfPresent(){

Set<String> winIds = driver.getWindowHandles();
System.out.println("Total windows -> "+ winIds.size());

if(winIds.size() == 2){
Iterator<String> iter = winIds.iterator();
String mainWinID = iter.next();
String popupWinID = iter.next();
driver.switchTo().window(popupWinID);
driver.close();
driver.switchTo().window(mainWinID);

}

}
}


M
Replied on 14/02/2016

package com.sample;

import java.util.Iterator;
import java.util.List;
import java.util.Set;
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;
import org.testng.annotations.Test;

public class ZWeBuy {

static WebDriver driver;

@Test
public void testProductPurchaseProcess() {
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("https://uk.webuy.com/search/index.php?stext=*&section=&catid=956");
closePopupIfPresent();

// xpath for all product names in this page
List<WebElement> allNames = driver.findElements(By
.xpath("//div[@class='searchRecord']/div[2]/h1/a"));
List<WebElement> allButtons = driver.findElements(By
.xpath("//div[@class='action']/div/a[2]/div/span"));

System.out.println("Total names = " + allNames.size());
System.out.println("Total buttons = " + allButtons.size());

allButtons.get(0).click();

WebDriverWait wait = new WebDriverWait(driver, 120);
wait.until(ExpectedConditions.elementToBeClickable(By
.xpath("html/body/div[5]/div[1]/div[3]/div[5]/div[1]/div[1]/div[3]/div/a[2]/div/span")));
System.out.println("I= " + 1 + " PRDCT: --- "
+ allNames.get(1).getText());
allButtons.get(1).click();
System.out.println("I= " + 2 + " PRDCT: --- "
+ allNames.get(2).getText());
allButtons.get(2).click();
allButtons.get(0).click();
System.out.println("I= " + 0 + " PRDCT: --- "
+ allNames.get(0).getText());
}

public static void closePopupIfPresent() {

Set<String> winIds = driver.getWindowHandles();
System.out.println("Total windows -> " + winIds.size());

if (winIds.size() == 2) {
Iterator<String> iter = winIds.iterator();
String mainWinID = iter.next();
String popupWinID = iter.next();
driver.switchTo().window(popupWinID);
driver.close();
driver.switchTo().window(mainWinID);

}

}
}