Reputation:
private IWebDriver webDriver;
[SetUp]
public void Setup()
{
webDriver = new FirefoxDriver();
webDriver.Navigate().GoToUrl("https://localhost:44311/");
}
[Test]
public void ButtonsCount_IsCorrect_IsTrue()
{
var buttons = webDriver.FindElement(...));
...
}
Simple scenario - website contains dynamically created buttons. I want to ensure count of buttons is the same as expected.
Catching it by XPath would be easy, except XPath leads to certain element, here we want to catch multiple dynamically created elements, but each one looks like this:
<a><i></i>Details</a>
The only difference is where href
leads, and I have skipped classes because they are not important here.
Conclusions are, it wouls be wise to search for all <a>
which contain string Details
. Now question is, how to do it in C# driver.
Upvotes: 1
Views: 86
Reputation: 526
You can use findElements
with xpath to find List of elements:
List<WebElement> elementName = driver.FindElements(By.XPath("//a[contains(text(),'Details')]"));
Upvotes: 1