如何在SeleniumJava中通过断言验证动态表

如何在SeleniumJava中通过断言验证动态表,java,selenium,Java,Selenium,我试过一个一个像这样生的 String element= driver.findElement(By.xpath("//*[@id='historyRow']/tbody/tr[1]/td[1]")).getText(); Assert.assertEquals(element, auto); 以下是Html代码: 我想验证是否在表中添加了第二个值,并验证是否显示了每个值的所有详细信息,并首先添加了前一个值。 如何验证所有原始数据 除了一个接一个,还有别的办法吗 2

我试过一个一个像这样生的

String element= driver.findElement(By.xpath("//*[@id='historyRow']/tbody/tr[1]/td[1]")).getText();

            Assert.assertEquals(element, auto);
以下是Html代码:

我想验证是否在表中添加了第二个值,并验证是否显示了每个值的所有详细信息,并首先添加了前一个值。 如何验证所有原始数据 除了一个接一个,还有别的办法吗


2019年11月19日美国东部时间上午09:34:10
abc汽车公司
编辑
评论
添加评论。评论
尝试以下代码: 请检查大括号的闭合情况

        // Grab the table 
        WebElement table = driver.findElement(By.id("View"));
        //get the size of the list of the rows
        List<WebElement> totalRows = table.findElements(By.tagName("tr"));
        int rows_count = totalRows.size();
        //Loop will execute till the last row of table.
            for (int row=0; row<rows_count; row++){
        //To locate columns(cells) of that specific row.
                List<WebElement> Columns_row = rows_table.get(row).findElements(By.tagName("td"));
        //To calculate no of columns(cells) In that specific row.
                int columns_count = Columns_row.size();
                System.out.println("Number of cells In Row "+row+" are "+columns_count);

        //Loop will execute till the last cell of that specific row.
                for (int column=0; column<columns_count; column++){
        //To retrieve text from that specific cell.
                    String celtext = Columns_row.get(column).getText();
                    System.out.println("Cell Value Of row number "+row+" and column number "+column+" Is "+celtext); 
        }
    });
//抓住桌子
WebElement表=driver.findElement(By.id(“视图”);
//获取行列表的大小
List totalRows=table.findElements(按.tagName(“tr”));
int rows_count=totalRows.size();
//循环将一直执行到表的最后一行。

对于(int row=0;rowPost您的相关HTML?您在其后面的文本位于第一行和第二列。而不是第一列。请尝试此操作。
String element=driver.findElement(By.xpath(“/*[@id='historyRow']]/tbody/tr[1]/td[2]”)。getText().trim();
        // Grab the table 
        WebElement table = driver.findElement(By.id("View"));
        //get the size of the list of the rows
        List<WebElement> totalRows = table.findElements(By.tagName("tr"));
        int rows_count = totalRows.size();
        //Loop will execute till the last row of table.
            for (int row=0; row<rows_count; row++){
        //To locate columns(cells) of that specific row.
                List<WebElement> Columns_row = rows_table.get(row).findElements(By.tagName("td"));
        //To calculate no of columns(cells) In that specific row.
                int columns_count = Columns_row.size();
                System.out.println("Number of cells In Row "+row+" are "+columns_count);

        //Loop will execute till the last cell of that specific row.
                for (int column=0; column<columns_count; column++){
        //To retrieve text from that specific cell.
                    String celtext = Columns_row.get(column).getText();
                    System.out.println("Cell Value Of row number "+row+" and column number "+column+" Is "+celtext); 
        }
    });