Try Catch block and If condition

Viewed 24

I'm trying to understand why is below if condition is behaving this way inside of the try catch block:

Example:

try {

    if (driver.getTitle().trim().equals("expected string"){
        test.log(Status.Pass, "Navigated to expected page");

        getElement(......).sendKeys(username);
        getElement(......).sendKeys(password);
        getElement(......).click();

    }
} catch (Exception e) {
    e.printStackTrace();
}

What is happening is when if conditon is true the next line of code where logging method is printing the confirmation it is not continuing to the next lines where it supposed to send keys and click a button. Instead, it is dropping down to the catch block. When I comment out the logging lines it is proceeding with the if condition properly executing next 3 lines.

How can I fix my code where after I log the step it does not jumps to catch block?

0 Answers
Related