• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • Programming Languages
    • Java Tutorials
    • Python Tutorials
    • JavaScript Tutorials
  • Automation Tools and Different Tools
    • Web Automation
      • Selenium with Java
        • Selenium Basic
        • Selenium Advance
        • Selenium Realtime
        • Framework
        • Selenium Interview
        • Selenium Videos
        • Selenium with Docker
      • Selenium with Python
      • WebdriverIO
        • Selenium Webdriver C# Tutorial
      • Cypress
      • Playwright
    • TestNG
    • Cucumber
    • Mobile Automation
      • Appium
    • API Testing
      • Postman
      • Rest Assured
      • SOAPUI
    • testRigor
    • Katalon
    • TestProject
    • Serenity BDD
    • Gradle- Build Tool
    • RPA-UiPath
    • Protractor
    • Windows Automation
  • Automation For Manual Testers
  • Services
  • Online Training
  • Contact us
  • About me
  • Follow us
    • Linkedin
    • Facebook Group
    • Facebook Page
    • Instagram

Automation

Selenium WebDriver tutorial Step by Step

You are here: Home / Uncategorized / Exceptions in Selenium WebDriver

Exceptions in Selenium WebDriver

March 16, 2015 by Mukesh Otwani 24 Comments

Before moving to Runtime Exception, you should be aware of Exception meaning.

Exception general meaning a condition that is not common, in Exceptions in Selenium WebDriver occurs many times in different scenarios let’s have a look to all exception one by one.

 

Exceptions in Selenium WebDriver
Exceptions in Selenium WebDriver

 

Exceptions in Selenium WebDriver

NoSuchElementException

This exception occurs when WebDriver is unable to identify the elements during run time. Due to wrong selector or selector, which is, not exist.
Example:-

driver.findElement(By.id("invalidid")).sendKeys("Mukesh");

 

ElementNotVisibleException

This Exception occurs when the element presence is in DOM, it is not visible.
Example:-
Hidden Elements, which has presence in DOM and it, is not visible. Visibility means the height and
width should be greater than zero. Hidden Elements are defined in HTML using of type=”hidden”.

driver.findElement(By.id("hiddenid")).sendKeys("Mukesh");

 

NoSuchFrameException

This Exception occurs when the driver is switching to an invalid frame, which is not available.
Example:-

driver.switchTo().frame(invalidindex);
(or)
driver.switchTo().frame("frame_z");

 

//frame_z is the name of the invalid frame
For frames indexing starts from Zero. Try to access the frame by providing invalid index.

NoAlertPresentException

This Exception occurs when the driver is switching to an invalid Alert, which is not available.
Example:-

driver.switchTo().alert().accept();

//Execute this command on browser without invoking the alert.

NoSuchWindowException

This Exception occurs when the driver is switching to an invalid Window, which is not available.
Example:-

driver.switchTo().window("invalidwindowname");

 

WebDriverException

This Exception occurs when the driver is performing the action after immediately closing the browser.
Example:-

driver.close();
driver.findElement(By.id("username")).sendKeys("Mukesh");

 

SessionNotFoundException

This Exception occurs when the driver is performing the action after immediately quitting the browser.
Example:-

driver.quit();
driver.findElement(By.id("username")).sendKeys("Mukesh");

 

StaleElementReferenceException

This Exception occurs when the Element belongs to a different frame than the current one. The user has navigated away to another page.

Example:-
WebElement element=driver.findElement(By.id("username"));// Element is available in parent window
driver.switchTo().window(Child_Window);//Switch to Child Window
element.sendKeys("Mukesh");//perform the action on the element which is not visible in the child window

Check out more exceptions here.

Thanks for visiting my blog. Please leave a comment if you have any issues in Selenium.

Keep in touch. Have a nice day 🙂

Filed Under: Uncategorized

Reader Interactions

Comments

  1. Avinash says

    July 5, 2021 at 11:45 AM

    Nice one, Thanks for clearly presenting with examples and explanation

    Reply
    • Mukesh Otwani says

      July 5, 2021 at 11:29 PM

      You’re welcome…:)

      Reply
  2. vivek says

    October 11, 2019 at 9:46 PM

    Really great content up to point not only theoretical.

    Reply
    • Mukesh Otwani says

      October 11, 2019 at 11:46 PM

      Thanks, Vivek…:)

      Reply
  3. Mahesh Chhetri says

    June 9, 2016 at 1:21 AM

    When i try use page system test, it has to return two data, one is return data and another is to return link for another page for testing keep continue. it has problem with this. can it be solve?

    Reply
    • Mukesh Otwani says

      June 9, 2016 at 1:46 AM

      Hi Mahesh, Sorry question is not clear,explain in brief please

      Reply
      • Mahesh Chhetri says

        June 9, 2016 at 2:13 AM

        I have a form
        and fileds name are

        firstName, Lastname, email, phone, cardnumber, month, year, cvv, address, city, state, zip

        When i test, it fills the field till “cvv” only and then this error comes and stop the test

        the error is

        Failed: element not visible
        (Session info: chrome=50.0.2661.102)
        (Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Windows NT 6.1 SP1 x86)

        Reply
        • Mukesh Otwani says

          June 14, 2016 at 9:23 PM

          Hey Mahesh,

          below article will help you.

          Reply
  4. Mahesh says

    June 9, 2016 at 1:16 AM

    Hi priti,

    ” Failed: element not visible
    (Session info: chrome=50.0.2661.102)
    (Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed09 83e7c4),platform=Windows NT 6.1 SP1 x86)
    ”
    Above this error comes while e2e testing, All the input, select testing well, but suddenly above error comes when it has to fill the data into another input box in the same form. how it can be solve. please

    Reply
    • Mukesh Otwani says

      June 9, 2016 at 1:48 AM

      Hi Mahesh,

      use explicit wait for above error.

      Reply
  5. sa says

    March 19, 2016 at 2:10 PM

    Hello sir
    If we click on a element(Enter button) Sometimes Dragging and sometimes it is throwing webdriver exception

    Reply
    • Mukesh Otwani says

      March 20, 2016 at 7:21 PM

      Hi Sagar,

      Any example for this?

      Reply
  6. Maheshwari B says

    March 17, 2016 at 9:18 PM

    Hi Mukesh,

    you have explained Runtime exceptions very nicely, it was very useful for me.
    But wanted to know details on other exceptions like nullpointerException, IOException etc.

    Reply
    • Mukesh Otwani says

      March 20, 2016 at 7:32 PM

      Hi Maheshwari,

      Thanks a ton.

      NullPointerException- When any variable point to null
      IOException- Whenever we deal with files this checked exception will come.

      Reply
  7. Senthil says

    February 18, 2016 at 10:24 AM

    The Use getAttribute() command is finding tooltip text… Thanks

    Reply
    • Mukesh Otwani says

      February 22, 2016 at 9:13 AM

      Great Senthil 🙂 I will try too soon.

      Reply
  8. Senthil says

    February 18, 2016 at 10:18 AM

    Hi,

    How to update quantity in the cart items. Because we have added 2 to 3 products in the cart items, when changing the quantity all 3 products quantity element name is same. how to get element those case?

    Thanks
    Senthil

    Reply
    • Mukesh Otwani says

      February 22, 2016 at 9:17 AM

      Hi Senthil,

      Could me please explain in using url as well?

      I hope you have solved it if not then let me know.

      Reply
  9. Satya says

    January 19, 2016 at 4:47 PM

    Hi

    Please share a post regarding how to solve class not found exception.

    Reply
    • Mukesh Otwani says

      January 20, 2016 at 1:04 AM

      Hi Satya,

      Can u explain in brief?

      Reply
  10. Kannan says

    October 30, 2015 at 10:31 PM

    Good post. Got some better understanding about exception handling 🙂

    Reply
    • Mukesh Otwani says

      October 30, 2015 at 11:22 PM

      Thanks Kannan 🙂

      Reply
  11. priti says

    March 16, 2015 at 11:32 PM

    hi mukesh
    I want to know how to Read ToolTip text in in Selenium-WebDriver

    Reply
    • Mukesh Otwani says

      March 17, 2015 at 12:20 AM

      Hi Priti,

      use mouse hover and use getText ()

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

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

Primary Sidebar

Free Selenium Videos

https://www.youtube.com/watch?v=w_iPCT1ETO4

Search topic

Top Posts & Pages

  • Selenium Webdriver tutorial for beginners
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Selenium Webdriver C# Tutorial
  • WHAT ARE YOUR EXPECTATIONS FROM US?

Stay connected via Facebook

Stay connected via Facebook

Archives

Footer

Categories

Recent Post

  • API Testing Using Postman And RestAssured
  • Disable Personalise Your Web Experience Microsoft Edge Prompt In Selenium
  • How To Fix Error: No tests found In Playwright
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Best and easy way to Group test cases in selenium

Top Posts & Pages

  • Selenium Webdriver tutorial for beginners
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Selenium Webdriver C# Tutorial
  • WHAT ARE YOUR EXPECTATIONS FROM US?