Selenium Webdriver Appium Complete TutorialSelenium Webdriver Appium Complete Tutorial
Automation Testing
  • Tools
    • Selenium
      • Selenium Java Tutorial
      • Selenium C# Tutorial
    • Appium
      • Appium Java Tutorial
      • Appium C#Tutorial
    • Katalon
  • Trainings
  • TestNG
  • Reports
    • Extent Reports
      • Extent Reports – Java
      • Extent Reports – Java -Version3
      • Extent Reports – C#
    • Vigo Reports
    • AT Excel Report
  • Excel
    • Apache POI – Java
    • Excel With C#
  • Interview Questions
    • Selenium Interview Questions
    • Java Interview Questions
    • C# Interview Questions
  • Demo Site
  • Practice Site
  • More…
    • AutoIt
    • Sikuli
    • Robot Class
    • File Upload
    • ScreenShot
      • AShot
      • ShutterBug
  • About
December 11, 2016

Selenium NoSuchElementException





Selenium NoSuchElementException is the most and frequent facing exception. You will definitely find this kind of exception while automating the application. In this blog we will see what are the reasons to face this exception and how we can overcome this exception in detail.

Below are the reasons to get this exception:

  1. The locator which you are using to locate the element is incorrect/changed.
  2. The element which you are looking is not rendered.
  3. Trying to find the element before it was rendered.

Locator is Incorrect/changed:

Here we have two possibilities that the locator which you have written to identify an element may be incorrect or sometimes after writing/capturing the code, if there are any changes in the application then the locator may change. In both scenarios tool will not able to identify the element and it will throw NoSuchElementException.

To overcome this, we need to take the element locator which is causing this issue and validate against the application that the locator is identifying/highlighting any element on the application or not? For this we can use Firefox add-ons i.e. firebug and firepath then you place the locator in the firepath and validate the same against application that it is highlighting the element or not?

And sometimes if you are not navigated to a particular page after clicking on a link or button then it will cause this issue as it will look for the element to interact in the new page but actually it is not navigated to that page. But here the actual error show that it is not able to find particular element but the issue is not with that element as the page not yet navigated to that page. This kind of situation is bit tricky, but we need to find these type of issues also. Best example for this is navigating to application using login page but if the credentials are wrong then you might get this issue.

To overcome this issue, we can capture the screenshots for these type of scenarios and can find the issues by looking into these screenshots.

Element Not Rendered:

It is bit difficult to find this as something is not rendering on the application then you need to debug the code and see what could be the real issue. If something is not rendering then that is a bug in the application.

Here if you use the first issue resolution then it will not work as if you try to highlight the element in the application using firebug and firepath then it will not show anything in the console. But this is not an issue with the locator instead the element is not rendering on the application.

To overcome this issue, we can capture the screenshots for these type of scenarios and can find the issues by looking into these screenshots.




Trying to find the element before it was rendered:

Sometimes we are trying to interact with an element which is not yet rendered on the application. Here also we will get the same kind of issue which we saw in the above. But in the above case the element is not completely rendering, here it is rendering but taking bit more time to load. Now a days lots of modern websites use technologies such as jQuery or AngularJS, which use the JavaScript to manipulate the DOM. And Our Selenium is very fast. In many cases, it’s ready to start interacting with your website before the JavaScript has finished doing its job.

To overcome this, we need to think that how a manual tester will test these kind of scenarios. They will wait until the element renders on the application. So, same way we need to wait to load that particular element. For this we will use Synchronization concept i.e. we need to stop the code execution until the element renders. For this we can use ExpectedConditions class and its methods to achieve this functionality.

Please watch the YouTube video for this blog for better understanding.



Share this post: on Twitter on Facebook on Google+

Selenium WebDriver Exceptions Selenium NoSuchFrameException

Related Posts

TAKING WEB ELEMENT SCREENSHOT IN SELENIUM

Selenium - Java

How to Capture WebElement Screenshot in Selenium Webdriver using selenium 4

avoid Switch to window

Selenium - Java

How to Avoid Switch To Window in Selenium WebDriver

webdrivermanager

Selenium - Java

No More Driver EXE files for Selenium Execution – Instead Use WebDriverManager

HANDLE TEXTBOXES IN SELENIUM

Selenium - Java

Handling Textboxes in Selenium

JAVASCRIPTEXECUTOR IN SELENIUM

Selenium - Java

JavaScriptExecutor in Selenium

ELEMENT NOT VISIBLE EXCEPTION

Selenium - C#, Selenium - Java

Selenium ElementNotVisibleException

NOSUCHWINDOW EXCEPTIONS

Selenium - C#, Selenium - Java

Selenium NoSuchWindowException

NOSUCHFRAME EXCEPTIONS

Selenium - C#, Selenium - Java

Selenium NoSuchFrameException

SELENIUM WEBDRIVER EXCEPTIONS

Selenium - C#, Selenium - Java

Selenium WebDriver Exceptions

HANDLING BASIC ELEMENTS IN SELENIUM

Selenium - C#, Selenium - Java

Handling Basic Elements in Selenium

Newsletter

Recent Posts

  • TAKING WEB ELEMENT SCREENSHOT IN SELENIUMHow to Capture WebElement Screenshot in Selenium Webdriver using selenium 4
    December 15, 2019
  • How To SWAP Two Numbers in Java Without using Temp VariableHow to SWAP Two Numbers in Java Without Temp variable or Without Third variable
    December 8, 2019
  • How to Swap Two Numbers in Java with Temp VariableHow to SWAP Two Numbers in Java using Temp Variable
    December 1, 2019
  • How to Read Properties file in JavaHow to Read Data From Properties File in Java
    November 27, 2019
  • Compare two arrays in java with out inbuilt functionsHow to Compare Two Arrays in Java without built-in functions
    November 16, 2019
© Selenium Webdriver Appium Complete Tutorial 2023