使用组合框和文本框的表格数据

时间:2017-01-13 04:43:59

标签: selenium selenium-webdriver

我是硒的新手。我有一个网页可以测试很多text boxescombo box。当按下sumbit按钮时,已插入texboxes的数据已插入并显示在其下方的表格中。

我如何从textboxcombobox获取每个数据,并将其与表格数据进行比较。

例如commbobox1数据为'IT资产',combobox2数据为'监控',combox 3数据为'Acer Monitor'。

插入后,会显示下表,其中包含如下所示的数据

Sl.NO |资产详情

1 | ITAsset /监视器/宏基

如果我们再次插入,它会出现在下面的表格中,序列号为2。

如果有任何错误,请忽略。

我正在使用带有selenium webdriver的Java,并且从excel传递数据

1 个答案:

答案 0 :(得分:0)

虽然问题非常不明确,因为您要在每个组合框值中验证的内容与表格中的文本或整个值的组合来自3个组合框。在运行时之前,当行数和列数未知时,您仍然可以使用以下代码动态处理Web表:

//To locate table.
  WebElement mytable = driver.findElement(By.xpath("**table-locator**/tbody"));

//To locate rows of table.
 List<WebElement> rows_table = mytable.findElements(By.tagName("tr"));

//To calculate no of rows In table.
  int rows_count = rows_table.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); 
相关问题