My try block throws NoSuchElementException but my catch block is unable to proceed. 
In my automation suite I get a page with btnOk element sometimes(first login everyday) so I am trying to handle the scenario where if the page comes then click on it and proceed otherwise continue any ways.
Code snippet below:
try {
    WebElement submitbuttonPresence=driver.findElement(By.id("btnOk"));
    submitbuttonPresence.click();
}
catch (NoSuchElementException e) {
    System.out.println(driver.getTitle());
}
                It seems you catch an incorrect exception. Try code below:
try {
    WebElement submitbuttonPresence=driver.findElement(By.id("btnOk"));
    submitbuttonPresence.click();
}
catch (org.openqa.selenium.NoSuchElementException e) {
    System.out.println(driver.getTitle());
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With