Display those flipkart product names which are out of stock | Selenium Training|Java|WebDriver|TestNG|Frameworks|Videos

Display those flipkart product names which are out of stock

M
Post on 31/08/2015

Dear All,

a) Test URL - http://www.flipkart.com/search?q=washing+machines+semi&as=off&as-show=off&otracker=start or Enter "washing machines semi" in seach box

b) Scroll down till no results found or all product loaded successfully

c) Get count of products which are out of stock and display those products names.

@all -- above c part is left where i am trapped ... here below is little code


// Get size of out of stock items

List<WebElement> out_Stock_Items = driver.findElements(By
.cssSelector("div[class='gd-col gu4']"));
System.out.println(out_Stock_Items.size());

// Display out of stocks products

for (int i = 0; i < out_Stock_Items.size(); i++) {
if(driver.findElement(By.cssSelector("a[class*='pu-status oos fk-uppercase']")).getText().equalsIgnoreCase("Out of Stock"))
{
[b:9c69wnz0]System.out.println(driver.findElement(By.cssSelector("a[data-tracking-id='prd_title']")).getText()); // This is wrong part where i am getting first item product text instead of out of stock product text[/b:9c69wnz0]

} else
{
System.out.println("Product is available");
}

}

M
Reply on 01/09/2015

class='gd-col gu4'
class*='pu-status oos fk-uppercase'
data-tracking-id='prd_title'

are these path working because experience tells me they won't they should give an exception.

have you tried By.Text("
Out of Stock
");

M
Reply on 01/09/2015

Yes these CSS are working as of now!

By the way i am still stuck with problem and it is code should fetch text of those [b:786woncx]Out Of stock product text only[/b:786woncx] not all 161 products.

Here is code as below -

List<WebElement> out_Stock_Items = driver.findElements(By
.cssSelector("div[class='gd-col gu4']"));
System.out.println(out_Stock_Items.size()); // overall products on page matching with input


for (int i = 0; i < out_Stock_Items.size(); i++) {
if (driver.findElement(By.xpath(("//a[contains(text(),'Out of Stock')]"))).getText()
.equalsIgnoreCase("Out of Stock")) // This condition should false as products are in stock unless it finds out of stock products but it is passing every time which is wrong

{
// if(driver.findElement(By.cssSelector("a[class*='pu-status oos fk-uppercase']")).getText().equalsIgnoreCase("Out of Stock")){
System.out
.println(driver
.findElement(
By.xpath(("//a[contains(text(),'Out of Stock')]/parent::div[1]/following-sibling::div[1]/child::div[1]/child::a[1]")))
.getText()); // fetch product name

} else {
System.out.println("Product is available");
}

}

M
Reply on 02/09/2015

do me a favor upload your java file here i'll take a look at it.

M
Reply on 02/09/2015

PFA java file

Reminding you mine TC objective is "Get those product names which are out of stocks"

Also if you want you can make required changes in code.

M
Reply on 03/09/2015

out_Stock_Items = driver.findElements(By
.xpath(".//*[@id='page-5']/div/div/div/div/div/div[1]/a[2]"));
List<WebElement> out_Stock_Items2 = driver.findElements(By
.xpath(".//*[@id='page-6']/div/div/div/div/div/div[1]/a[2]"));

use these but they will change so they might only work for limited time.

M
Reply on 03/09/2015

Any permanent fix then ?

I know they will work for few days only and more over i dont think it is stable xpath!!!

so we do have any other suggestions?

M
Reply on 03/09/2015

except for the xpath i gave you I cannot find any other stable elements.