Selenium Webdriver - Fetching Table Data

后端 未结 7 1951
执笔经年
执笔经年 2021-02-04 08:03

I want to fetch data from tables in UI. I know about looping through rows and columns using \"tr\" and \"td\". But the one the table I have is something like this:



        
7条回答
  •  时光说笑
    2021-02-04 08:33

    // Grab the table
    WebElement table = driver.findElement(By.id("searchResultsGrid"));
    
    // Now get all the TR elements from the table
    List allRows = table.findElements(By.tagName("tr"));
    // And iterate over them, getting the cells
    for (WebElement row : allRows) {
        List cells = row.findElements(By.tagName("td"));
        for (WebElement cell : cells) {
            System.out.println("content >>   " + cell.getText());
        }
    }
    

    using cell.getText() would simply work

提交回复
热议问题