当检查网页上是否给出了价格时,我不想检查确切的值(因为该值可能会发生变化),我首先要检查页面对象是否存在(无错误等),然后再检查它正在返回一个数值。
这可能吗?
使用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");
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句