Advertisement

How to handle NoSuchElement Exception in Java Selenium

How to handle NoSuchElement Exception in Java Selenium This video clearly explains how to handle nosuchelement exception in Java Selenium.

Learn more at

What is NoSuchElementException?
NoSuchElementException is one of the different WebDriver Exceptions and this Exception occurs, when the locators (i.e. id / xpath/ css selectors etc) we mentioned in the Selenium Program code is unable to find the web element on the web page.

Common Exceptions in Selenium WebDriver:
NoSuchElementException.
NoSuchWindowException.
NoSuchFrameException.
NoAlertPresentException.
InvalidSelectorException.
ElementNotVisibleException.
ElementNotSelectableException.
TimeoutException.

Script:
Hi guys.

So I have written a code to open the Chrome browser and enter the URL of actitime application, and there's a button so I just wanted to click on that button.

So let me execute this program.
So this is launching with the browser.
It is entering the URL of the an application and I'm getting an error.
So let's see.
What is that exception?
So the exception tells no such element exception.
What's the meaning of this exception means there is no element called as login to perform the click action on that element now, let me check what my ex path expression written is correct or not.
Let me go to that application and let me inspect this element right-click inspect.
So your is the element.
Let me copy this and let me write double forward slash tag as div and the shortcut for the text is there so what is that element is login, correct?
Right, but I'm getting error But If You observe it carefully if I inspect there is a space.
Can you see the space after logging?
Space is also a character.
That's a reason I was getting no such element exception now if I go there and give a space and save this program and let me execute this script.
This is launching me the Chrome browser enter the URL of then application.
And this is loading until the page gets loaded.
It is clicking on the login and I'm getting an error message.
So what is an issue?
So when you get this no such element exception whenever the address of an element and strong.
So we usually do this mistakes, like upper cases lower cases or spaces spaces also character in selenium.
So, how do we resolve this?
No such thing.
Exception by writing a by identifying the correct element.
So by identifying the correct element we can resolve this no such element exception.
So I hope you guys have understood how do you resolve as no such element exception.
Login now to access all the courses designed by the experts of SkillRary.
www.skillrary.com

For more info, visit Skillrary.


For regular updates on latest courses and assessments or certifications,
Follow us on Facebook,


Follow us on Twitter,


Follow us on LinkedIn,


Follow us on Instagram,

Selenium

Post a Comment

0 Comments