Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 99018

Condition to check if element is present in DOM

$
0
0

I am using if block to check if product is in stock or out of stock. but it is not executing the else block , also I don't want to put else part in catch block.

I have used isDisplayed, isEnabled but still it is not working.

try {
    if (driver.findElement(By.xpath("//span[contains(text(),'Currently unavailable.')]"))
            .isEnabled()) {
        o1.put("STOCK", "Out of Stock");
    } else {
        o1.put("STOCK", "In Stock");
    }
} catch (NoSuchElementException e) {
    e.printStackTrace();
}

Viewing all articles
Browse latest Browse all 99018

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>