Web table in selenium web driver

Web table in selenium web driver

Simple function for click on edit image for particular record

    WebElement element=driver.findElement(By.xpath("//*[@id='service']/div/div[1]"));
      List<WebElement> rowCollection=element.findElements(By.xpath("//*[@id='table-list']/tbody/tr"));
      System.out.println("Numer of rows in this table: "+rowCollection.size());
      //Here i_RowNum and i_ColNum, i am using to indicate Row and Column numbers.
      int i_RowNum=1;
      for(WebElement rowElement:rowCollection)
      {
            List<WebElement> colCollection=rowElement.findElements(By.xpath("td"));
            int i_ColNum=1;
            for(WebElement colElement:colCollection)
            {
                 System.out.println("Row "+i_RowNum+" Column "+i_ColNum+" Data "+colElement.getText());
                 i_ColNum=i_ColNum+1;
               
                 if (colElement.getText().equals("ritesh"))
                 {
                      //td[2] is not dynamic,In my case edit image is on td[2] for each tr
                      WebElement editClick = driver.findElement(By.xpath("//*[@id='table-list']/tbody/tr["+i_RowNum+"]/td[2]/a/img"));
                      editClick.click();
                      System.out.println("testing foecom="+"Row "+i_RowNum+" Column "+i_ColNum+"");
                      break;
                 }
         }
          i_RowNum=i_RowNum+1;
       }
}
}

No comments:

Post a Comment