title: Selenium relative locator searches from a WebElement extremely slow
body: <p>I am using Selenium 2.0, Firefox 11.0, and Java to process a table. I have a table element composed of td cells, some which contain text included in a span element, others which contain input elements which have text in their value attributes. My goal is to get the text of every cell so I can output the table contents and compare them against expected values. I thought I would just do something like this:</p>
  
  <pre><code>Locate the table WebElement by id
  List&lt;WebElement&gt; cells = tableElem.findElements(By.xpath(".//td"));
  </code></pre>
  
  <p>Then I would loop through all the cells and run findElements with the xpath ".//input" and if the list was empty I would run getText on the webElement, and if the list wasn't empty I would run getAttribute on the input element.</p>
  
  <p>But to my surprise, this took several minutes to run on firefox (I'm afraid to try it on IE, which is where its supposed to be tested). When I debug it is obvious that the bottleneck is the .//input search from the td which is killing me. It is upwards of ten seconds, and so even with just a few cells my tests are taking forever. I've tried all sorts of minor variations to the xpath, tried going to css selectors, and continue to get the same results. </p>
  
  <p>I want some advice about how to either tackle this problem differently or how to optimize my current method. I was hoping this would only take a couple of seconds.</p>
  
  <p>I've included some sample code that should illustrate the slowdown I'm experiencing. This is not the website I'm screen scraping, but the slowness is the same:</p>
  
  <pre><code>    webDriver.navigate().to("https://accounts.google.com/NewAccount");
      List&lt;WebElement&gt; TDxpath = webDriver.findElements(By.xpath("//td"));
      List&lt;WebElement&gt; TDcss = webDriver.findElements(By.cssSelector("td"));
      for (WebElement td : TDcss) {
          List&lt;WebElement&gt; q = td.findElements(By.cssSelector("input"));
      }
      for (WebElement td : TDxpath) {
          List&lt;WebElement&gt; r = td.findElements(By.xpath(".//input"));
      }
  </code></pre>