samedi 18 juillet 2020

Find Variable in Table with Selenium and Java

I am a beginner and I am trying to find a variable in a dynamic table with Selenium. I think it's not that hard, but I did something wrong, so maybe someone could take a look. Here ist what I tried:

String  prioName = "AutoPrio";

//to get the number of rows
String row = "//*[@id=\"app\"]/div/div/div[2]/div/div/div/div[3]/div[1]/table/tbody/tr";
                int rowData = driver.findElements(By.xpath(row)).size();
                
//to get the number of columns 
                String col="//*[@id=\"app\"]/div/div/div[2]/div/div/div/div[3]/div[1]/table/tbody/tr[2]/td";
                int colData = driver.findElements(By.xpath(col)).size();
        

//search in Table for variable 
                String firstPart = "//*[@id=\"app\"]/div/div/div[2]/div/div/div/div[3]/div[1]/table/tbody/tr[";
                String secondPart ="]/td[";
                String thirdPart ="]";
                
                String text = null;
                
                for (int i = 1; i <= rowData; i++) {
                    for (int j = 1; j <= colData; j++) {
                        String finalPart = firstPart+i+secondPart+j+thirdPart;
                        text = driver.findElement(By.xpath(finalPart)).getText();
                        System.out.print(text+" / "); //This is working. Prints the table
                        if (text == prioName) {
                            System.out.println("Found in Table!"); //this is not working  
                        }
                    }
                    System.out.println();
                }

What it gives me looks like this:

  • / Test / - /
  • / test / 12 /
  • / AutoPrio / 10 /
  • / AutoPrio / 10 /

This ist just the Information, that is saved in the table

Thank you!!

Aucun commentaire:

Enregistrer un commentaire