cd.findElement(By.xpath("//*[@id=\"ctl00_loginControls_txtUserName\"]")).sendKeys("avijeet.mund");
cd.findElement(By.xpath("//*[@id=\"ctl00_loginControls_txtPassword\"]")).sendKeys("Password1");
cd.findElement(By.xpath("//*[@id=\"ctl00_loginControls_btnSubmit\"]")).click();
test.log(LogStatus.PASS, "Log on to the application Successfully");
test.log(LogStatus.FAIL, "Log in failed due to Invalid Username or Password");
the above code is written for log in to application. i want if log in successful then pass message should display and if log in failed then failed message should display.
For my above code both statement is displaying in the report.attached the screenshot for more details.Please advise.
Instructor
Ashish Thakur Replied on 30/08/2019
you need to surround the code in a try-catch block.
try {
cd.findElement(By.xpath("//*[@id=\"ctl00_loginControls_txtUserName\"]")).sendKeys("avijeet.mund");
cd.findElement(By.xpath("//*[@id=\"ctl00_loginControls_txtPassword\"]")).sendKeys("Password1");
cd.findElement(By.xpath("//*[@id=\"ctl00_loginControls_btnSubmit\"]")).click();
test.log(LogStatus.PASS, "Log on to the application Successfully");
} catch (Exception e) {
test.log(LogStatus.FAIL, "Log in failed due to Invalid Username or Password");
}