title: webdriver java. Large webtable, how to make finding a specific value fast
body: <p>On a very large webtable, typically hundreds of rows and many columns, how can we make it fast to find a particular value? Ideally I want to specify a column name, look for cell data only for that column and retrieve a specified cell value. </p>
  
  <p>My code is slow, it picks up all the data from all the cells in the table and then verifies each one of them to find the specified value. This consumes considerable amount of time.</p>
  
  <pre><code>public static void selectColumnValue(String tableXpath, String columnValue){ 
       String str, found = "false";
      // String colValue = null;
       WebElement table = driver.findElement(By.xpath(tableXpath));       
       List&lt;WebElement&gt; rows=table.findElements(By.xpath(tableXpath+"/tbody/tr"));
       for(WebElement row:rows)
       {
           List&lt;WebElement&gt; cols =row.findElements(By.xpath("td"));
           for(WebElement col:cols)
           {
               str=col.getText().trim();
               //System.out.println(str);
               if(str.matches(columnValue))
               {
                   //List&lt;WebElement&gt; vals=row.findElements(By.xpath("td"));
                   col.click();
                   found="true";
  
               }
           }
           if(found.matches("true")){
               break;
           } } }
  </code></pre>
  
  <p>HTML for a couple of rows is as below:</p>
  
  <pre><code>    &lt;table id="T536870949" class="BaseTable" title="" style="top: 16px;"&gt;
  &lt;colgroup cols="5"&gt;
  &lt;col style="width: 139px;"/&gt;
  &lt;col style="width: 140px;"/&gt;
  &lt;col style="width: 139px;"/&gt;
  &lt;col style="width: 140px;"/&gt;
  &lt;col style="width: 119px;"/&gt;
  &lt;/colgroup&gt;
  &lt;tbody&gt;
  &lt;tr class="hiddentablehdr"&gt;
  &lt;th scope="col"&gt;Device Name&lt;/th&gt;
  &lt;th scope="col"&gt;Site ID&lt;/th&gt;
  &lt;th scope="col"&gt;Monitoring SSA&lt;/th&gt;
  &lt;th scope="col"&gt;Manufacturer&lt;/th&gt;
  &lt;th scope="col"&gt;Model&lt;/th&gt;
  &lt;/tr&gt;
  &lt;tr class="" arrow="0" tabindex="0"&gt;
  &lt;td class="BaseTableCellOdd BaseTableCellOddColor BaseTableStaticText" scope="row" style="width: 139px;" title="001000"&gt;
  &lt;nobr class="dp " style="text-align: right; width: 139px;"&gt;
  &lt;/td&gt;
  &lt;td class="BaseTableCellOdd BaseTableCellOddColor BaseTableStaticText" style="width: 140px;"&gt;
  &lt;nobr class="dp " style="text-align: right; width: 140px;"&gt;
  &lt;span style="float:left;"&gt;NTA001&lt;/span&gt;
  &lt;/nobr&gt;
  &lt;/td&gt;
  &lt;td class="BaseTableCellOdd BaseTableCellOddColor BaseTableStaticText" style="width: 139px;" title="0019839"&gt;
  &lt;nobr class="dp " style="text-align: right; width: 139px;"&gt;
  &lt;span style="float:left;"&gt;0019839&lt;/span&gt;
  &lt;/nobr&gt;
  &lt;/td&gt;
  &lt;td class="BaseTableCellOdd BaseTableCellOddColor BaseTableStaticText" style="width: 140px;"&gt;
  &lt;nobr class="dp " style="text-align: right; width: 140px;"&gt;
  &lt;span style="float:left;"&gt;unknown&lt;/span&gt;
  &lt;/nobr&gt;
  &lt;/td&gt;
  &lt;td class="BaseTableCellOdd BaseTableCellOddColor BaseTableStaticText" style="width: 119px;"&gt;
  &lt;/tr&gt;
  &lt;tr class="" arrow="1" tabindex="0"&gt;
  &lt;td class="BaseTableCell BaseTableCellColor BaseTableStaticText" scope="row" style="width: 139px;" title="001001"&gt;
  &lt;nobr class="dp " style="text-align: right; width: 139px;"&gt;
  &lt;span style="float:left;"&gt;001001&lt;/span&gt;
  &lt;/nobr&gt;
  &lt;/td&gt;
  &lt;td class="BaseTableCell BaseTableCellColor BaseTableStaticText" style="width: 140px;" title="001"&gt;
  &lt;nobr class="dp " style="text-align: right; width: 140px;"&gt;
  &lt;span style="float:left;"&gt;001&lt;/span&gt;
  &lt;/nobr&gt;
  &lt;/td&gt;
  &lt;td class="BaseTableCell BaseTableCellColor BaseTableStaticText" style="width: 139px;" title="0019839"&gt;
  &lt;nobr class="dp " style="text-align: right; width: 139px;"&gt;
  &lt;span style="float:left;"&gt;0019839&lt;/span&gt;
  &lt;/nobr&gt;
  &lt;/td&gt;
  &lt;td class="BaseTableCell BaseTableCellColor BaseTableStaticText" style="width: 140px;"&gt;
  &lt;nobr class="dp " style="text-align: right; width: 140px;"&gt;
  &lt;span style="float:left;"&gt;DMI&lt;/span&gt;
  &lt;/nobr&gt;
  &lt;/td&gt;
  &lt;td class="BaseTableCell BaseTableCellColor BaseTableStaticText" style="width: 119px;"&gt;
  &lt;nobr class="dp " style="text-align: right; width: 119px;"&gt;
  &lt;span style="float:left;"&gt;Manufacturer=xyz&lt;/span&gt;
  &lt;/nobr&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  
  ........
  </code></pre>