Get the Dynamic table data from gui in selenium webDriver -


i working on web based application testing selenium. on 1 page content dynamically loaded in table. want table data, geting "org.openqa.selenium.nullpointerelementexception" in line.

webelement table = log.driver.findelement(by.xpath(tablexpath)); 

i tried following complete code.

public int selectfromtable(string tablexpath, string comparevalue, int columnnumber) throws exception {     webelement table = log.driver.findelement(by.xpath(tablexpath));     list<webelement> rows = table.findelements(by.tagname("tr"));     int flag = 0;     (webelement row : rows) {         list<webelement> cells = row.findelements(by.tagname("td"));         if (!cells.isempty() && cells.get(columnnumber).gettext().equals(comparevalue)) {             flag = 1;             thread.sleep(1000);             break;         } else {             thread.sleep(2000);             flag = 0;         }     }     return flag; } 

i calling above method like

string tablexpath = ".//*[@id='event_list']/form/div[1]/table/tbody/tr/td/div/table"; selectfromtable(tablexpath, eventtype, 3); 

my html page like

<table width="100%">     <tbody style="overflow: auto; background-color: #ffffff">         <tr class="trodd">             <td width="2%" align="center">             <td width="20%" align="center"> account </td>             <td width="20%" align="center"> enter collection </td>             <td width="20%" align="center">             <td width="20%" align="center"> 10 </td>             <td width="20%" align="center"> 1 </td>         </tr>     </tbody>     <tbody style="overflow: auto; background-color: #ffffff">         <tr class="treven">             <td width="2%" align="center">             <td width="20%" align="center"> account </td>             <td width="20%" align="center"> resolved collection </td>             <td width="20%" align="center">             <td width="20%" align="center"> 10 </td>             <td width="20%" align="center"> 1 </td>         </tr>     </tbody> </table> 

my solution similar case - wanted row number table, given column contains specific text.

// method searches in given column of table , return number of row // first value spotted (title row counts 0 row , // skipped). if no value found 0 returned. given column number // starts 1.  public integer gettablerownumberwithvalue(string tableid, string value,         integer columnnumber) {      webelement table = getdriver().findelement(by.id(tableid));     list<webelement> rows = table.findelements(by.tagname("tr"));      int j = 0;     int = 0;     (webelement row : rows) {         // skip title row counts 0 row.         if (i > 0) {             if (row.findelements(by.tagname("td")).get(columnnumber - 1)                     .gettext().equals(value)) {                 j = i;                 break;             }         }         i++;     }     return j; } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

android - Inheriting from Theme.AppCompat* -