How to check if element exist or not without using try-catch

You can use FindElements. FindElement would throw a NoSuchElementException. FindElements on the other hand returns a empty List. You can check if the list is empty and return null if true.

IList<IWebElements> elements = driver.FindElements(By.Id("abcd"));
Assert.True(elements.Count==0, "Field is editable");

Browse More Popular Posts

Leave a Comment