Agile Testing Alliance hosted it’s first #ATATalk – Episode 1 on 10th March 2021 from 6:00 pm – 7:00 pm (IST).
About the Session:
In this community session, Pallavi talked about the different exceptions we come across Selenium, the reason behind them and some of the exception handling techniques the different programming languages provides us with.
EXCEPTIONS IN SELENIUM
Errors and Exceptions are part and parcel of programming. I have always believed and experienced that we learn more from the mistakes we make, even in programming. And when we use a tool which implementation is largely driven by the programming language we are using to implement, we should be aware about the inner architecture of the tool so to make better decisions and code structure to use it. Selenium is one such tool, which is the centre point of this discussion. A tool which allows us to automate the browser, and what we do with it is entirely up to us, as mentioned on the https://www.selenium.dev the website of Selenium. When we write code, we are bound to introduce errors into it. We are bound to make mistakes unintentionally most of the times. And the errors we make in our code can be broadly classified as – a. Syntax Error b. Runtime Error c. Logical Error
We see this error when we make a mistake at the syntax level of the code, and it is caught by the smart IDE’s now available to us.
The code may look fine to us, but at the time of execution it will throw an error/exception.
This error is caused, when at the algorithm level our solution itself is wrong.
Exceptions, which we encounter are generally raised from the run time errors, or they might be caused because of other environmental issues around the code. In this ATA Talk, we discussed about specific exceptions with respect to Java as a programming language, which we see while working with Selenium, and where can we know more about them.
All selenium exceptions, are derived from WebDriverException class in the Selenium API’s and following are the list of packages where we can find it being implemented-
A major set of exceptions implemented, are found in the org.openqa.selenium package itself –
Indicates that a click could not be properly executed because the target element was obscured in some way.
Thrown to indicate that although an element is present on the DOM, it is not in a state that can be interacted with.
Thrown to indicate that although an element is present on the DOM, it is not selectable, and so is not able to be
Thrown to indicate that although an element is present on the DOM, it is not visible, and so is not able to be interacted
Indicates that activating an IME engine has failed.
Indicates that IME support is not available.
Thrown when attempting to add a cookie under a different domain than the current URL.
Indicates that a WebElement is in a state that means actions cannot be performed with it.
Indicates that a user has tried to access an alert when one is not present.
Thrown by ContextAware.context(String) WebDriver.switchTo().context(String name)}.
Thrown by WebDriver.findElement(By by) and WebElement.findElement(By by).
Thrown by WebDriver.switchTo().frame(int frameIndex) and WebDriver.switchTo().frame(String frameName).
• NoSuchSessionException T
Thrown by any command being called after WebDriver.quit().
Thrown by WebDriver.switchTo().window(String windowName).
Thrown when an async execute script command does not complete in enough time.
Indicates that a session could not be created.
Indicates that a reference to an element is now “stale” — the element no longer appears on the DOM of the page.
Thrown when a command does not complete in enough time.
Thrown when a driver fails to set a cookie.
Used to indicate that a command used
In Selenium we have a NotFoundException, which a child of WebDriverException, acts as a parent for some of the common exceptions we encounter
To handle exceptions in java as a programming language we use the try catch block of code. And as a best practice we need to use the try catch where the logic is of the code. If the code can give rise to more than one exception, we can also write one try with multiple catch blocks.
The other two kinds of exception we come across are as follows
The stale element exception is generally raised when we are trying to work on an element which is no longer associated with the DOM.
And element not interactable exception is raised by an element, which though may appear in the dom, but is hidden or not visible, thus selenium cannot work with it.
If you are using other programming languages to implement selenium, please understand that the class of Selenium which handles exception, the types and explanation of these exceptions will remain same irrespective of the language used for implementation. But how one handles these exceptions will depend on the language chosen and the architecture chosen to implement your code.
For more information on it you can visit the following links
|Slide Share Presentation||https://www.slideshare.net/ATASlides/atatalk-episode-1-session-on-selenium-exceptions-by-pallavi-sharma|
ATATALK is a new community initiative of ATA
ATA has held many conferences and meetups in the past years. In 2020, we managed to hold 2 virtual conferences and 6 virtual meetups. This year we started off with a virtual SeleniumSummit21 . While we are still grappling with Covid situation and physical events are yet to kick off. We thought about having a 45 minute to 60 minute live learning / interactive capsules. Thus allowing us to break the monotonous regime and quickly get in new learning bytes. Enabling us to connect with each other and with the budding/established speakers. #ATATALK is to fulfill this need. The idea around #ATATALK is to give all budding speakers a chance to share their ideas and knowledge with the community.
ATATALK is thus all about discussing fresh ideas, innovative thoughts, solving problems, treading on unchartered waters or learning something which is important in todays scenario and in the process creating a larger community of thought leadership.
Everybody is welcome to attend #ATATALK and also be a speaker at #ATATALK.
Participants also got chance to interact with Pallavi live in this wonderful #ATATalk initiative.
Here is the video link of the session:
For upcoming events, please visit our ATAEvents.org