【问题标题】:Check that a value on a webpage is numerical in selenium webdriver在 selenium webdriver 中检查网页上的值是否为数字
【发布时间】:2015-09-15 15:40:22
【问题描述】:

当检查网页上是否给出了价格时,我不想检查确切的值(因为这可能会发生变化),我首先想检查页面对象是否存在(没有错误等) ) 然后它返回一个数值。

这可能吗?

【问题讨论】:

标签: selenium testing selenium-webdriver automation automated-tests


【解决方案1】:

使用 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;
    }
}

您可以在测试脚本中使用

Assert.True(PriceObjectValidation(), "Price element is not numeric value");

【讨论】:

    猜你喜欢
    • 2015-11-23
    • 2014-06-23
    • 2014-09-23
    • 2020-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-19
    相关资源
    最近更新 更多