Automation Question

Hello Team,

I have an automation question. On our website product page the product price is shown in 2 different formats :

If Product is on sale :

If Product not on sale :

I am continuously having difficulty trying to identify programmatically withing the script if the product is on sale or not. If it is on sale pick up the sale price i.2 $45.89 in the 1st screenshot or else pickup regular price


I think I would maybe have an if statement…something like…

if element has span then click
else click

in other words, I would try looking for that element where the sale price resides, and if it’s there select it. I’d have to poke around with writing it, but that’s first pass…maybe it’s helpful?

1 Like

It looks like if a product is on sale, some extra elements are present:


These are not present when a product is not on sale:


So you just need an xpath that looks for one these extra elements:

//h2[@class='price price-preview' and ./span]

To answer the question “is the product on sale”, you would check that this element is present:

WebUI.verifyElementPresent(findTestObject("path/to/my/object"), 5)

1 Like

@Amanda_Perkins1 @Brandon_Hein Thanks for your reply. Based on the approaches and solutions you shared I created 3 Objects

For the product on sale :



For the product not on sale :


Then, I created the script using if Statement

if (WebUI.verifyElementPresent(findTestObject('Page_PDP/Product_Price_Update/Sale_Price'), 5, FailureHandling.OPTIONAL)) {
    Sale_Price = WebUI.getText(findTestObject('Page_PDP/Product_Price_Update/Product_Price_Before_Sale'))

    WebUI.println('The Product is on Sale and Sale Price is  : ' + Sale_Price)


    Actual_Price = WebUI.getText(findTestObject('Page_PDP/Product_Price_Update/Product_Price_No_Sale')).replace('$', '')

    WebUI.println('The Product is not on Sale and Price is  : ' + Actual_Price)

This works fine on a product not on sale

2019-07-09 14:13:57.058 DEBUG testcase.Product_Price                   - 14: else
2019-07-09 14:13:57.059 DEBUG testcase.Product_Price                   - 1: Actual_Price = getText(findTestObject("Page_PDP/Product_Price_Update/Product_Price_No_Sale")).replace("$", "")
2019-07-09 14:13:57.096 DEBUG testcase.Product_Price                   - 2: println("The Product is not on Sale and Price is  : " + Actual_Price)
The Product is not on Sale and Price is  : 75.00

But when I run it on product on sale I am getting both Product_Price_Before_Sale and Sale_Price in the output of Variable Sale_Price . Can you please help me in figuring out how I can only get the Sale price

2019-07-09 14:22:13.878 DEBUG testcase.Product_Price                   - 12: delay(ShortDelay)
2019-07-09 14:22:15.884 DEBUG testcase.Product_Price                   - 13: if (verifyElementPresent(findTestObject("Page_PDP/Product_Price_Update/Sale_Price"), 5, OPTIONAL))
2019-07-09 14:22:15.905 DEBUG testcase.Product_Price                   - 1: Sale_Price = getText(findTestObject("Page_PDP/Product_Price_Update/Product_Price_Before_Sale"))
2019-07-09 14:22:15.946 DEBUG testcase.Product_Price                   - 2: println("The Product is on Sale and Sale Price is  : " + Sale_Price)
The Product is on Sale and Sale Price is  : $37.00$29.89

If you just want the sale price, use this xpath instead:

//h2[@class='price price-preview']/span

1 Like

@Brandon_Hein This worked perfectly, Thanks

1 Like