I am running a test on a web page that may or may not have a certain element. The procedure is the following: I fill out the form, then click "Search" button. When the browser opens a new url, I need to choose an element_1, but if it does not exist I must choose element_2.
WebElement element = driver.findElement(By.xpath("//....")) || driver.findElement(By.xpath("//..."));
element.click();
// This does not do the trick, is there any other way? Is it possible to do without try and catch?