如何验证页面中特定区域中的内容

时间:2011-10-05 07:18:34

标签: selenium

我们如何验证页面中特定区域下的内容。假设我需要在contentPane中验证一个单词。单词可能出现在span,title或p中。

<div id="contentPane">
  <span>Something</span>
  <title> Title </>
  <p> Paragraph has actual content </p>
</div>

1 个答案:

答案 0 :(得分:1)

假设您使用的是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属性将返回所有嵌套元素的纯文本,因此哪个特定元素(spantitlep)无关紧要包含文字。