You could alternatively do:
driver.findElements(By.id("...")).size() != 0
Which saves the nasty try/catch
P.S.:
Or more precisely by @JanHrcek here
!driver.findElements(By.id("...")).isEmpty()
More Related Contents:
- WebDriver: check if an element exists? [duplicate]
- What is the difference between ChromeDriver and WebDriver in selenium?
- Element MyElement is not clickable at point (x, y)… Other element would receive the click
- Selenium webdriver: Modifying navigator.webdriver flag to prevent selenium detection
- How to resolve ElementNotInteractableException: Element is not visible in Selenium webdriver?
- Selenium WebDriver throws Exception in thread “main” org.openqa.selenium.ElementNotInteractableException
- How to switch to the new browser window, which opens after click on the button?
- WebDriver – wait for element using Java
- How can I ask the Selenium-WebDriver to wait for few seconds in Java?
- How to handle windows file upload using Selenium WebDriver?
- Unable to import org.openqa.selenium.WebDriver using Selenium and Java 11
- Switch tabs using Selenium WebDriver with Java
- Cannot resolve constructor FirefoxDriver(org.openqa.selenium.firefox.FirefoxProfile)
- pageLoadTimeout in Selenium not working
- The type FluentWait is not generic; it cannot be parameterized with arguments error for FluentWait Class through Selenium and Java
- Selenium WebDriver: Wait for complex page with JavaScript to load
- How to select an item from a dropdown list using Selenium WebDriver with java?
- Equivalent of waitForVisible/waitForElementPresent in Selenium WebDriver tests using Java?
- Difference between webdriver.get() and webdriver.navigate()
- org.openqa.selenium.WebDriverException: chrome not reachable – when attempting to start a new session
- Selenium WebDriver and DropDown Boxes
- java.lang.IllegalAccessError: tried to access method com.google.common.util.concurrent.SimpleTimeLimiter. when using Selenium-Java 3.5.1 or above
- Why do some elements exist but not interactable/displayed?
- Does Selenium v3.141 support Java 13?
- Selenium WebDriver StaleElementReferenceException
- Is there a proved mouseOver workaround for FirefoxDriver in Selenium2?
- How to resolve, Stale element exception? if element is no longer attached to the DOM?
- Compound class names are not supported error in WebDriver
- How to set proxy authentication in PhantomJS using selenium?
- How to mouse hover using java through selenium-webdriver and Java