user15515307
user15515307

Reputation:

C# Selenium Driver - get all elements by text

        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

Answers (1)

Lia
Lia

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

Related Questions