2017-04-19 46 views
0

我想將網絡表的行和列存儲到數組列表中,然後驗證數據。我可以打印行,但我將如何存儲行。如何在arraylist中存儲webtable,然後在selenium webdriver中驗證數據

public void verifyTable() { 

String Test = driver.findElement(loggedinas).getText(); 


boolean isDue = false; 
isDue = UtilClass.isElementPresent(driver, TableContent); 

if (isDue) { 
    if (isDue = driver.findElement(TableContent).getText() != null) 
     ; 
    System.out.println("Action Required = " + isDue); 

    WebElement table_element = driver.findElement(Table); 
    List<WebElement> tr_collection = table_element 
      .findElements(TableRow); 
    System.out.println("Number Of Due = " + tr_collection.size()); 

    int row_num, col_num; 

    row_num = 1; 
    for (WebElement trElement : tr_collection) { 
     List<WebElement> td_collection = trElement.findElements(By.xpath("td")); 

     System.out.println("--NUMBER OF COLUMNS = " 
       + td_collection.size() + "--"); 

     col_num = 1; 
     for (WebElement tdElement : td_collection) { 
      // System.out.println("Pending # "+row_num+", col # "+col_num+ 
      // "text="+tdElement.getText()); 

      System.out.printf(" # " + tdElement.getText(), " ID " 
        + tdElement.getText()); 
      col_num++; 

     } 
     row_num++; 

    } 

謝謝!

+0

你嘗試使用二維的ArrayList? –

+0

感謝@ApurvChatterjee工作正常,只是好奇,如果表有重複的EmpID,但有差異。 Emp名稱,然後如何使用value.contains(「EmpID」) –

+0

嗨@sumit我相信我們可以有一個單獨的線程相同。 –

回答

1

我做了類似的事情,請檢查該功能波紋管,這會給你一個想法

public void manageUserDataGrid(WebDriver driver){ 
    WebElement table = driver.findElement(By.xpath("//*[@id='ReportTable']")); 
    List<WebElement> rows = table.findElements(By.tagName("tr")); 
    List<WebElement> column = table.findElements(By.tagName("td")); 
    List<String> value = new ArrayList<String>(); 

    System.out.println(rows.size()); 

     for (int j=0; j<column.size(); j++){ 
      System.out.println(column.get(j).getText()); 
      value.add(column.get(j).getText()); 
     } 
     if (value.contains("coadminss")){ 
      System.out.println("Value found"); 
     } 
     else{ 
      System.out.println("Not Found"); 
     } 
} 
相關問題