I'm trying to verify if a link is present or not -- but -- if it's not present, I want my script to continue executing (close the browser, etc).
The purpose of my script is to determine if a 'Delete Address' link is present or not. If it is, I click on the link and delete the address. This works fine. If the link is not present however, I just want to continue execution without triggering an exception. My code below triggers an exception if the link is not there.
Thanks for any help...
try {
String txt = driver.findElement(By.linkText("Delete Address")).getText().trim();
Assert.assertTrue(txt.equals("Delete Address"));
Alert javascriptprompt = driver.switchTo().alert();
javascriptprompt.accept();
} catch (NoSuchElementException e) {
}