0

I have this page in my application that has a table that has a column with some link text. This list is dynamic and I'm trying to validate that a particular link text displays. It still passes even when the link text isn't there. Help is appreciated.

    public void getMessage(String message) throws Exception {
    String expectedMessage= data.loadData(data.getMessages().getAbsolutePath()).getProperty(message);
    List<WebElement> tableLink = driver.findElements(By.className("messageLink"));

    for (WebElement element : tableLink) {

        if (element.getText().equals(expectedMessage))
            
        {
            System.out.println("Message Exists");

            return;

        }
    }

}
sam2013
  • 21
  • 1
  • 4
  • Just to clarify I did add a print statement and saw that one of the expected edit checks wasn't in the tableLink list, instead of failing the test passed. I'm trying to figure out why this is happening. Its making me crazy. – sam2013 Apr 15 '21 at 20:33
  • Solves this by following the top rated answer: https://stackoverflow.com/questions/11454798/how-can-i-check-if-some-text-exist-or-not-in-the-page-using-selenium – sam2013 Apr 16 '21 at 15:21

2 Answers2

0

You might have to throw an exception if tableLink list is empty.

Additionally, you can also consider throwing an exception for an unexpected input.

Bugman
  • 191
  • 6
0

I would add a print statement within the for-loop in order to see what element.getText().equals(expectedMessage) produces each iteration, your code looks solid so I am thinking there might be an issue in the element.getText() method. If you post the code for the method i would gladly take a look to see if I catch some easy-to-miss thing!