Home » Software Testing » Automation Testing » Selenium WebDriver Tutorial » Handling Element Not Found Exception In Selenium WebDriver

Handling Element Not Found Exception In Selenium WebDriver

IF you are a Selenium WebDriver  Automation tester than most probably you would have gone through this situation, In which you have faced one exception that speaks “Element not found“.

So why not, we get together and find first whether the element is on-page or not and then we perform the action on it.

Case 1:
Why not use implicit wait or explicit wait before the line of code that finds the element for a specific action. There might be possibility like element has not to be loaded into DOM and due to this exception is coming and stating something related to this “Element not found”

Case 2:
If Case 1: is not able to handle your problem then why not we use this line of code

Case 3: If you are using ChromeDriver and trying to click on the certain button than
try the same code on Firefox because Chrome Driver throws an exception that speaks like Element is not present at the location with the co-ordinates and if it working on firefox then get back to code and in place of the simple driver.findelement try javascriptExecutor to click the button and it will work.

Case 4:
Why not we use isDisplayed() method first in If a condition like this

Case 5:

Before using any of the elements in code, try to find whether the locator has been correctly written and check the locator is picking the right set of WebElement from the Web-Page. If you want to learn how to find whether your locator is correct or not, in that case, go and read post

Inspecting Elements for writing XPath, CSS Selector in Chrome

Good Luck!!!!

8 thoughts on “Handling Element Not Found Exception In Selenium WebDriver”

  1. With case 2 and case 4 what if i=0 and if the element is not displayed, you are still gonna wait otherwise your script fails!

  2. Pingback: WebDriver’s most popular Commands | Abode QA

  3. Pingback: Handling Multiple Windows in WebDriver | Abode QA

  4. Pingback: Email your failing Selenium WebDriver scripts’ Stack Trace to your Email Id | Abode QA

  5. Pingback: Unexpected error launching Internet Explorer. Protected Mode must be set to the same value | Abode QA

  6. Dear, Dwarika

    I have been a regular visitor of your website and i thank u for your efforts.
    i am new to selenium webdriver and i am continue facing an issue of “modal dialogue issue”.

    Could u help me that how to handle this issue in firefox.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: