title: Compare two tables on screen using Selenium with Java
body: <p>I have to compare two tables as a QA. I am extracting values of the both using the following code in Selenium. </p>
  
  <p>FYI: I have used two different browser windows and different variable names for each of the two tables (i.e. one in each environment)</p>
  
  <pre><code>String first_part = ".//*[@id='Matrix']/tbody/tr[";
      String second_part = "]/td[";
      String third_part = "]/a";
  
  
      //rows of the matrix table (Always 7)
      for (int i=4; i&lt;=7; i++){
          //Columns of the matrix table (Always 4)
          for (int j=1; j&lt;=4; j++){
              //Prepare final xpath for each cell value
              String matrix_cell_path =   first_part+i+second_part+j+third_part;
                  //Retrieve cell-value
                  String matrix_cell_data= driver.findElement(By.xpath(matrix_cell_path)).getText();
                  System.out.print("matrix_cell_data["+i+"]["+j+"]= "+matrix_cell_data + " ");
          }
              System.out.println("");
              System.out.println("");  
      }
  
  
      String first_part_Prod = ".//*[@id='Matrix']/tbody/tr[";
      String second_part_Prod = "]/td[";
      String third_part_Prod = "]/a";
  
      //rows of the matrix table (Always 7)
      for (int k=4; k&lt;=7; k++){
          //Columns of the matrix table (Always 4)
          for (int l=1; l&lt;=4; l++){
              //Prepare final xpath for each cell value
              String matrix_cell_path_Prod = first_part_Prod+k+second_part_Prod+l+third_part_Prod;
                  //Retrieve cell-value
                  String matrix_cell_data_Prod = second_driver.findElement(By.xpath(matrix_cell_path_Prod)).getText();
                  System.out.print("matrix_cell_data_Prod["+k+"]["+l+"]= "+matrix_cell_data_Prod + " ");
          }
              System.out.println("");
              System.out.println("");  
      }
  </code></pre>
  
  <p>I want to verify if each cell in both the tables are equal. how to do it?</p>
  
  <p>I have used the following check, but shows error: </p>
  
  <p><strong>matrix_cell_data cannot be resolved to a variable.</strong> </p>
  
  <pre><code>   //Matrix Data - Content Check:
      try {
          matrix_cell_data = matrix_cell_data_Prod;
          System.out.println("Great");
      }catch (Exception ex2){
          System.out.println("Exception"+ex2);
      }
  </code></pre>