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
");
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");
}
}
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.
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.
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?