I have a scenario, where page takes me to a screen where it has a message like the functionality is not enabled. hence you are here. Then i need to navigate to the settings page and has to enable it & reload the form to verify the web elements.
Initially everything was fine, second time when i ran the code. i have encountered no such element exception. because the setting was disabled initially, which has been enabled through the automated script and it is enabled now and i can see the form elements. I have to execute the system setting code only when the element is found else i have to skip the code.
I tried below way, but i still get no such element found error
if(driver.findElement(By.id("ViewErrorMessage")) != null) {
String errorMsg = driver.findElement(By.xpath("//*[@id=\"ctl00_pnlViewErrorMessage\"]")).getText();
Assert.assertEquals(errorMsg, "Form is disabled, Hence you are here. Enable the form");
//system setting code
driver.findElement(By.xpath("//input[@name='btnSignin']")).click();
Thread.sleep(2000);
driver.findElement(By.xpath("//img[@id='imgLogo']")).isDisplayed();
}else{
//code to verify form elements goes here..
}
error is reported at the if condition. when element is not found, i am assuming it has to execute else loop but it always fails at the same point. could anyone please help.