0
我們如何驗證頁面中特定區域下的內容。假設我需要驗證contentPane中的單詞。這個詞可能會以span,title或p的形式出現。如何驗證頁面中特定區域中的內容
<div id="contentPane">
<span>Something</span>
<title> Title </>
<p> Paragraph has actual content </p>
</div>
我們如何驗證頁面中特定區域下的內容。假設我需要驗證contentPane中的單詞。這個詞可能會以span,title或p的形式出現。如何驗證頁面中特定區域中的內容
<div id="contentPane">
<span>Something</span>
<title> Title </>
<p> Paragraph has actual content </p>
</div>
假設你使用Selenium 2(如果你的情況允許,你應該這樣做),這很容易。
C#代碼
IWebDriver driver = //whatever browser driver you are using
IWebElement contentPane = driver.FindElement(By.Id("contentPane"));
string text = contentPane.Text;
bool wordPresent = text.Contains("some word");
的Text
屬性將返回所有的嵌套元素的純文本所以它並不重要的特定元素(span
,title
,或p
)含有的文本。
下面的說明會起作用嗎? ('// div [@ id ='contentPane'] [contains('New York','NY','N.Y.')]「)); 如果不能,請你幫忙實現類似的任何其他方式? – Unni
isTextPresent需要一個字符串。我會使用text()XPath函數而不是contains()。 – prestomanifesto
我實際上想斷言contentPane有'紐約','紐約','紐約'的任何一個。這些話..任何人都可以寫出確切的命令 – Unni