-2

When checking to see if a price is given on a webpage, I don't want to check the exact value (as that's subject to change), I first want to check that the page object exists (no error, etc.) and then that it's returning a numerical value.

Is this possible?

AHiggins
  • 7,029
  • 6
  • 36
  • 54
Tester13
  • 7
  • 4
  • 1
    can you share more details. which languages do you use? what did you try? it is a very general question. – Mahsum Akbas Sep 15 '15 at 15:44
  • you can get text of element and check it is numerical or not – Mahsum Akbas Sep 15 '15 at 15:45
  • 1
    possible duplicate of [How to check if a String is a numeric type in Java](http://stackoverflow.com/questions/1102891/how-to-check-if-a-string-is-a-numeric-type-in-java) – SiKing Sep 15 '15 at 15:47

1 Answers1

0

With C#

private IWebElement priceElement = driver.FindElement(By.Id("price_value"));

public bool PriceObjectValidation()
{
    decimal outDecim;

    try
    {
        string str = priceElement.Text;
        bool isDecimal = decimal.TryParse(str, out outDecim);

        return isDecimal;

    }
    catch (NoSuchElementException e)
    {
        throw new Exception("Price element is not found");
    }
    catch (FormatException)
    {
        return false;
    }
}

In your Test Script you can use

Assert.True(PriceObjectValidation(), "Price element is not numeric value");
Arsey
  • 347
  • 1
  • 2
  • 8