Например: войдите на веб-страницу с текстом (неизвестным пользователю), а затем убедитесь, что он имеет такой же текст на другой странице.
Вы можете выбрать что-то вроде:
Найти Тело HTML объект для первой страницы, используя XPath , например:
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 = "/9609531/kak-proverit-tekst-na-odnoi-stranitse-a-zatem-podtverdit-chto-eto-tot-zhe-tekst-na-drugoi-stranitse-s-pomoschy-selenium"; 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); } }
Пример вывода: