title: XPath - way to select an element based on partial string
body: <p>If I have several hyperlinks on the page listed in a grid, and I just want to get focus to the first hyperlink, is there a way to get ref to an a tag's href based on part of the href text?</p>
  
  <p>example, lets say the page has a bunch of hyperlinks with car names:</p>
  
  <pre><code>&lt;a href="/Customers/7"&gt;Adam Backwell&lt;/a&gt;
  &lt;a href="/Customers/12"&gt;Eric Mebratu&lt;/a&gt;
  &lt;a href="/Customers/5"&gt;Dave Johnson&lt;/a&gt;
  &lt;a href="/Customers/54"&gt;Tom Rogan&lt;/a&gt;
  </code></pre>
  
  <p>So I want to do something like this for my xPath:</p>
  
  <pre><code>"//table[@id='{0}']/a[href{1}]", usersGridId, "/Customers/");
  </code></pre>
  
  <p>So get the first hyperlink with /Customers/ in its href.  I don't know if you can do just partial string matches..or in other words regex with XPath can you? In this case I don't want to be dependent on the CustomerId because I don't know what that Id will be as the grid is dynamic.  All I care about it grabbing reference to the first hyperlink in the grid list, no matter who it is.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Forgot to add that I'm using XPath with the Selenium Web framework.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>duh, just realized I already have ref to that table (you don't see that code here though..sorry)</p>
  
  <p>So I'm doing like grid.FindElement(By.XPath(xPath)); where grid references already a table element.  Within this table is a tbody so I'm tryign to get to the a element like this now:</p>
  
  <pre><code>IElement gridTable = GetCustomerGrid(); // now represents the table element that holds the customer list
  xPath = string.Format("/tbody[@id='{0}']/a[1](contains(@href,'{1}')]", usersGridContainerId, "/Customers");
  IWebElement hyperlink = gridTable.FindElement(By.XPath(xPath));
  </code></pre>
  
  <p>no luck on this one either.</p>
  
  <p>also tried the following based on the updated code above:</p>
  
  <pre><code>string.Format("/tbody[@id='{0}']/a(contains(@href,'{1}')]",usersGridContainerId, "/Customers"); // did not find the hyperlink
  string.Format("/tbody[@id='{0}']/a[1](starts-with(@href,'{1}')]",usersGridContainerId, "/Customers"); //invalid XPath Syntax error
  string.Format("//tbody[@id='{0}']/a(contains(@href,'{1}')]",usersGridContainerId, "/Customers");
  string.Format("//tbody[@id='{0}']/a(starts-with(@href,'{1}')]",usersGridContainerId, "/Customers");
  </code></pre>
  
  <p>Here's the structure of the page where I'm trying to get at the hyperlink</p>
  
  <pre><code>&lt;div class="table"&gt;
      &lt;table id="customerList"&gt;
          &lt;thead&gt;
              &lt;tr&gt;
                  &lt;th class="column1"&gt;ID&lt;/th&gt;
                  &lt;th class="column2"&gt;Name&lt;/th&gt;
                  &lt;th class="column3"&gt;Email&lt;/th&gt;
              &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody id="custListContainer"&gt;
              &lt;tr&gt;
                  &lt;td class="column1"&gt;7&lt;/td&gt;
                  &lt;td class="column2"&gt;&lt;a href="/Customers/7"&gt;Joe Smith&lt;/a&gt;&lt;/td&gt;
                  &lt;td&gt;someDude@gmail.com&lt;/td&gt;
              &lt;/tr&gt;
          .. next user, and so on
          &lt;/tbody&gt;
      &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>tried this, no luck:</p>
  
  <pre><code>string xPath = (string.Format("//tbody[@id={0}]/tr/td/a(starts-with(@href, {1})", usersTableId, " /Customers/"));
  OurSeleniumDriverInstance.FindElement(By.XPath(xPath ));
  </code></pre>