top of page

Exceptions In Selenium Webdriver

An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions. When an error occurs within a method, the method creates an object and hands it off to the runtime system.

​

The common exceptions you may come across and their understanding is listed below

​

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("Name");


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("Name");


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("Name");//perform the action on the element which is not visible in the child window

​

Firefox Not Connected 

Firefox browser upgraded toop new version.


ElementIsNotSelectable  

An attempt was made to select an element that cannot be selected.
 

UnknownCommand 

The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource.
 

InvalidElementState  

An element command could not be completed because the element is in an invalid state (e.g. attempting to click a disabled element).
 

UnknownError

An unknown server-side error occurred while processing the command.
 

JavaScriptError

An error occurred while executing JavaScript code.
 

XPathLookupError

An error occurred while searching for an element by XPath.
 

Timeout

An operation did not complete before its timeout expired.
 

InvalidCookieDomain

An illegal attempt was made to set a cookie under a different domain than the current page.
 

UnableToSetCookie

A request to set a cookie’s value could not be satisfied.
 

UnexpectedAlertOpen

A modal dialog was open, blocking this operation
 

NoAlertOpenError

An attempt was made to operate on a modal dialog when one was not open.
 

ScriptTimeout

A script did not complete before its timeout expired.
 

InvalidElementCoordinates

The coordinates provided to an interactions operation are invalid.


IMENotAvailable

IME was not available.
 

IMEEngineActivationFailed

An IME engine could not be started.
 

InvalidSelector

Argument was an invalid selector (e.g. XPath/CSS).

​

bottom of page