-2

當檢查網頁上是否給出價格時,我不想檢查確切的值(因爲這可能會發生變化),我首先想要檢查頁面對象是否存在(沒有錯誤等),然後它返回一個數字值。檢查網頁上的數值是否在硒鼓驅動器中是數字

這可能嗎?

+1

你可以分享更多的細節。你使用哪種語言?你嘗試了什麼?這是一個非常普遍的問題。 –

+0

你可以得到元素的文本,並檢查它是否是數字 –

+1

可能重複的[如何檢查字符串是否是Java中的數字類型](http://stackoverflow.com/questions/1102891/how-to-check -if-A-字符串是-一個數字型在-java的) – SiKing

回答

0

用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");