Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In a word, no, none of the <code>FindElement()</code> strategies support using regular expressions for finding elements. The simplest way to do this would be to use <code>FindElements()</code> to find all of the links on the page, and match their <code>.Text</code> property to your regular expression. </p> <p>Note though that if clicking on the link navigates to a new page in the same browser window (i.e., does not open a new browser window when clicking on the link), you'll need to capture the exact text of all of the links you'd like to click on for later use. I mention this because if you try to hold onto the references to the elements found during your initial <code>FindElements()</code> call, they will be stale after you click on the first one. If this is your scenario, the code might look something like this:</p> <pre><code>// WARNING: Untested code written from memory. // Not guaranteed to be exactly correct. List&lt;string&gt; matchingLinks = new List&lt;string&gt;(); // Assume "driver" is a valid IWebDriver. ReadOnlyCollection&lt;IWebElement&gt; links = driver.FindElements(By.TagName("a")); // You could probably use LINQ to simplify this, but here is // the foreach solution foreach(IWebElement link in links) { string text = link.Text; if (Regex.IsMatch("your Regex here", text)) { matchingLinks.Add(text); } } foreach(string linkText in matchingLinks) { IWebElement element = driver.FindElement(By.LinkText(linkText)); element.Click(); // do stuff on the page navigated to driver.Navigate().Back(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload