how to locate webelement with innertext

Sam picture Sam · Jun 13, 2012 · Viewed 8.1k times · Source

I use selenium with C# to write a test, but now I face a problem.

Here is my html. How can I locate the "100" on the web page?

< ul>

 < li class=""> 100 < /li>

 < li class=""> 200 < /li>

 < li class=""> 300 < /li>

 < li class=""> 400 < /li>

 < li class=""> 500 < /li>

< /ul>

Answer

Arran picture Arran · Jun 13, 2012
IWebDriver Driver = new FirefoxDriver();
IWebElement element = Driver.FindElement(By.XPath("//li[text()=' 100 ']"));