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

Check Solution