title: Selenium locator for <label for="x">
body: <p>With ASP.NET the tag IDs are pretty volatile so to make my tests more robust I want to locate elements by their label texts. I have played some with WatiN and it does this perfectly but that project seem kind of dead nowadays so I thought I'd look into Selenium as well before I decide on a framework.</p>
  
  <p>I have html that looks something like this</p>
  
  <pre><code>&lt;label for="ctl00_content_loginForm_ctl01_username"&gt;Username&lt;/label&gt;:
  &lt;input type="text" id="ctl00_content_loginForm_ctl01_username" /&gt;
  </code></pre>
  
  <p>I don't want to type:</p>
  
  <pre><code>selenium.Type("ctl00_content_loginForm_ctl01_username", "xxx");
  </code></pre>
  
  <p>That is too reliant on the ID. In WatiN I'd write:</p>
  
  <pre><code>browser.TextField(Find.ByLabelText("Username")).TypeText("xxx");
  </code></pre>
  
  <p>Is there a way to do this in Selenium?</p>