Can anyone please help me with the following scenarios I want to use with if/else conditions. I'm using java with Testng Eclipse.
1) If login is successful and navigates you to Home page, avoid try/catch2) If login fails, go to try block.

driver.findElement("username")).sendKeys(u sername); driver.findElement("password")).sendKeys(p assword); driver.findElement("login")).submit(); try{ Assert.assertFalse(driver.findElement(By.xpath("//div[@class='errorMsg']")).getText().matches("Username or password incorrect. Try again.")); } catch(Throwable t){"Username Or Password is Incorrect."); } Assert.assertEquals(actualTitle, title,"Home is not accessible!");

Check Solution