例如:登录一个包含文本(用户未知)的网页,然后验证其在另一页面上是否具有相同文本。
答案 0 :(得分:0)
您可以选择类似的东西
driver.FindElement(By.XPath("//body"))
示例代码:
driver.Url = "https://stackoverflow.com";
string firstPageText = driver.FindElement(By.XPath("//body")).GetAttribute("innerText");
HashSet<string> firstPageLines = new HashSet<string>(firstPageText.Split('\n'));
driver.Url = "https://stackoverflow.com/questions/56366177/how-do-i-verify-text-on-one-page-then-validate-it-is-that-same-text-on-another-p";
string secondPageText = driver.FindElement(By.XPath("//body")).GetAttribute("innerText");
HashSet<string> secondPageLines = new HashSet<string>(secondPageText.Split('\n'));
foreach (string line in firstPageLines) {
if (secondPageLines.Contains(line)) {
Console.WriteLine("This line is present in both pages: " + line);
}
}
示例输出: