简体   繁体   中英

Selenium webdriver IsTextPresent (on the page more than once)

I am using selenium web driver to determine whether a string of text exists more than twice on a page, as it should only appear once.

I can use Assert.IsTrue(this.Driver.IsTextPresent("body", "string")), but I was looking for a while to see if the text was on the page more than once.

You can do this easily with FindElements :

driver.FindElements(By.XPath("//*[contains(text(),'TEXT')]")).Count;

If Count > 1 , then the text is present more than once on the page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM