TestingDocs.com
    Software Testing website
    • Automation
      • Selenium
      • JBehave Framework
    • Tutorials
      • MySQL Tutorials
      • Testlink
      • Maven
      • Git
    • IDEs
      • IntelliJ IDEA
      • Eclipse
    • Flowcharts
      • Flowgorithm
      • Raptor
    • About

    Selenium

    Understanding common Selenium Exceptions

    Overview

    In this tutorial, we will try to simulate the common Selenium exceptions for better understanding. We might get these exceptions during the tests, we will look at code snippets for clarity and the run outputs.

    NoSuchWindowException

    When we try to switch to an window which is not present gives us this exception as shown in the below example.

    Once you open Microsoft Bing search open page there would be no window as mentioned below.

    @Test
    public void sampleTest() throws MalformedURLException
    {
    driver.get("https://www.bing.com");
    driver.switchTo().window("NoWindowWithThisName");
    driver.close();
    }

     

    Run output of the test method:

    FAILED: sampleTest
    org.openqa.selenium.NoSuchWindowException: Unable to locate window “NoWindowWithThisName”.

    The above code snippet throws us an exception, as we are trying to switch to an window that is not present.

    SeleniumNoSuchWindowExample

     

    NoSuchFrameException

    Now we try to simulate no such frame exception. Usually, we get this when we try to switch to an frame that is not present.
    Also, this is similar to window exception, we encounter frame exception while switching to frame that is not present.

    @Test
    public void sampleTest() 
    {
    driver.get("https://www.bing.com");
    driver.switchTo().frame("NoFrameWithThisName");
    driver.close();
    }

     

    Run output:

    FAILED: sampleTest
    org.openqa.selenium.NoSuchFrameException: No frame element found by name or id NoFrameWithThisName

    SessionNotFoundException

    This exception in encountered, when we try to access the Remote webdriver instance after calling the quit(0 method.Below is sample snippet :

    Mostly, we use remote web driver while testing using selenium grid or cloud testing.

    @Test
    public void sampleTest() 
    {
    driver.get("https://www.bing.com");
    driver.quit();
    driver.get("https://www.bing.com");
    }

     

    Run output:

    org.openqa.selenium.remote.SessionNotFoundException: Session ID is null. Using WebDriver after calling quit()?

    NoAlertPresentException

    @Test
    public void sampleTest() 
    {
    try{
     driver.switchTo().alert().accept();
     }
     catch (NoAlertPresentException nape){ 
     nape.printStackTrace(); }
    }

     

    Run output:

    org.openqa.selenium.NoAlertPresentException: No alert is present (WARNING: The server did not provide any stacktrace information)

    We get this exception when we try to perform an action i.e., either accept() or dismiss() when there is no alert present.

    NotConnectedException

    Caused by: org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms.

    We get this exception, when Firefox is not connected. Also, the communication between the web driver tests and the Firefox browser is somehow broken. Furthermore, this happens when we are trying to run on machines with firewall enabled , port blocked by anti virus programs. Make sure we use compatible Firefox browser binaries. If we encounter this exception try to find root cause by investigating one cause at the time.

    —

    Selenium Tutorials on this website:

    https://www.testingdocs.com/selenium-webdriver-tutorial/

    Official Website:

    https://www.selenium.dev/

    Related Posts

    Windows 10 Settings

    Selenium /

    Add Microsoft Webdriver on Windows OS

    Download Selenium Components

    Selenium /

    Getting Started with Selenium Webdriver

    LambdaTest Testing Cloud SaaS Platform

    Selenium /

    LambdaTest – Testing Cloud SaaS Platform

    Selenium /

    Selenium 3.0 and Mozilla GeckoDriver

    SauceLabs Website

    Selenium /

    Run an Example Test on SauceLabs

    ‹ Custom Firefox Profile for Selenium Webdriver› Challenges in Selenium Automation Testing

    Recent Posts

    • ChatGPT Plans Free and PlusChatGPT Subscription Plans
    • Stellar Converter for Database ToolStellar Converter for Database
    • Stellar MySQL Log AnalyzerStellar Log Analyzer for MySQL
    • Stellar Repair for MySQLStellar Repair for MySQL
    • ChatGPT IntroductionChatGPT Capabilities
    • How to secure your SQL Database: Tips and Tricks
    • ChatGPT4 Conversational AI FeaturesChatGPT4 Conversational AI Features
    • Trends in Software EngineeringShaping the Future of Development: Exploring Key Trends in Software Engineering
    • Java PerformanceImproving Java Performance with Multithreading
    • QDrant Vector DatabaseOpen-source Vector Databases
    • Difference between PHP and JavaScript?
    • Bing AI Browser Web ContentBing Conversation Styles
    • ChatGPT PreviewChatGPT Introduction
    • Open Source AI Frameworks TensorFlowOpen Source AI Frameworks
    • Artificial Intelligence Tools

    Back to Top

    Links

    • Contact
    • Privacy Policy
    • Cookie Policy

    www.TestingDocs.com