I am trying to extract the value of an HTML table element from a website and compare it to a user input value but it seems that my if-else loop is not being recognized when I run the program. It works with no errors but I am not getting an output from Eclipse, I'm new to Selenium Java and still learning.
See my code below:
String inputString = basePrem;
try {
//Print to console the value of Base Prem
WebElement table = driver.findElement(By.xpath(".//td[text()='Base Premium']/following-sibling::*"));
List<WebElement> allrows = table.findElements(By.tagName("tr"));
List<WebElement> allcols = table.findElements(By.tagName("td"));
for(WebElement row: allrows){
List<WebElement> Cells = row.findElements(By.tagName("td"));
for(WebElement Cell:Cells){
if (Cell.getText().contains(basePrem))
{
System.out.print("Base Premium = "+ basePrem + " ");
}
else if (!Cell.getText().contains(basePrem))
{
System.out.print("Base Premium = " + basePrem + " ");
break;
}
}
}
}
catch (Exception e) {
errorMessage = "Value discrepancy";
System.out.println(errorMessage + " - " + e.getMessage());
driver.close();
}
}
Also, inputString is where I input the value I use for comparison (I use a separate excel file for testing)
Since the control is not going inside my if loop, I probably have some logical error?
Aucun commentaire:
Enregistrer un commentaire