title: Get the Dynamic table data from gui in selenium webDriver
body: <p>I am working on a web based Application that I am testing with Selenium. On one page the content is dynamically loaded in table. I want to get the Table data, i am geting a "org.openqa.selenium.NullPointerElementException" in this line.</p>
  
  <pre class="lang-java prettyprint-override"><code>WebElement table = log.driver.findElement(By.xpath(tableXpath));
  </code></pre>
  
  <p>I tried the following complete code.</p>
  
  <pre class="lang-java prettyprint-override"><code>public int selectfromtable(String tableXpath, String CompareValue, int columnnumber) throws Exception {
      WebElement table = log.driver.findElement(By.xpath(tableXpath));
      List&lt;WebElement&gt; rows = table.findElements(By.tagName("tr"));
      int flag = 0;
      for (WebElement row : rows) {
          List&lt;WebElement&gt; cells = row.findElements(By.tagName("td"));
          if (!cells.isEmpty() &amp;&amp; cells.get(columnnumber).getText().equals(CompareValue)) {
              flag = 1;
              Thread.sleep(1000);
              break;
          } else {
              Thread.sleep(2000);
              flag = 0;
          }
      }
      return flag;
  }
  </code></pre>
  
  <p>I am calling the above method like</p>
  
  <pre class="lang-java prettyprint-override"><code>String tableXpath = ".//*[@id='event_list']/form/div[1]/table/tbody/tr/td/div/table";
  selectfromtable(tableXpath, eventType, 3);
  </code></pre>
  
  <p>my html page is like</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;table width="100%"&gt;
      &lt;tbody style="overflow: auto; background-color: #FFFFFF"&gt;
          &lt;tr class="trOdd"&gt;
              &lt;td width="2%" align="center"&gt;
              &lt;td width="20%" align="center"&gt; Account &lt;/td&gt;
              &lt;td width="20%" align="center"&gt; Enter Collection &lt;/td&gt;
              &lt;td width="20%" align="center"&gt;
              &lt;td width="20%" align="center"&gt; 10 &lt;/td&gt;
              &lt;td width="20%" align="center"&gt; 1 &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
      &lt;tbody style="overflow: auto; background-color: #FFFFFF"&gt;
          &lt;tr class="trEven"&gt;
              &lt;td width="2%" align="center"&gt;
              &lt;td width="20%" align="center"&gt; Account &lt;/td&gt;
              &lt;td width="20%" align="center"&gt; Resolved From Collection &lt;/td&gt;
              &lt;td width="20%" align="center"&gt;
              &lt;td width="20%" align="center"&gt; 10 &lt;/td&gt;
              &lt;td width="20%" align="center"&gt; 1 &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>