Check if an element exists using WebDriver

IF you are a Selenium WebDriver  Automation tester than most probably you would have gone through this situation, In which you have faced one exception that speaks “Element not found”.

So why not, we get together and find first whether element is on page or not and than we perform the action on it.

Case 1:
Why not use implicit wait or explicit wait before the line of code that find the element for specific action. There might be possbility like element has not be loaded in to DOM and due to this exception is coming

Case 2: If Case 1: is not able to handle your problem than why not we use this line of code

Int i=driver.findElement(By.xapth(“your xpath”)).size();
System.out.println(“Finally we got the element and now do the action on it”);

Case 3: If you are using ChromeDriver and trying to click on certain button than
try the same code on Firefox because Chrome Driver throw an exception that speaks like Element is not present at location with the co-ordinates

Case 4:
Why not we use isDisplayed() method first in If condition like this

if(dirver.findElement(“Id of Element”)).isDisplayed())
{ //now perform the action on this element

Hope this will help you in finding the element on your testing webpage.

Good Luck!!!!


This entry was posted in Selenium WebDriver and tagged , , , , , by Dwarika Dhish Mishra. Bookmark the permalink.

About Dwarika Dhish Mishra

My name is Dwarika Dhish Mishra, its just my name and I am trying to bring the worth of my name in to actions and wants to be the solution not the problem. I believe in spreading knowledge and happiness. More over I am fun loving person and like travelling a lot. By nature I am a tester and a solution maker. I believe in the tag line of “Idea worth spreading” . For the same, I have created this blog to bring more and more learning to tester fraternity through day to day learning in professional and personal life. All contents are the part of my learning and so are available for all..So please spread the contents as much as you can at your end so that it could reach to every needful people in testing fraternity. I am pretty happy that more and more people are showing interest to become the part your Abode QA blog and I think this is good sign for us all because more and more content would be before you to read and to cherish. You may write or call me at my Email id: Cell: 9999978609

7 thoughts on “Check if an element exists using WebDriver

  1. Pingback: WebDriver’s most popular Commands | Abode QA

  2. Pingback: Handling Multiple Windows in WebDriver | Abode QA

  3. Pingback: Email your failing Selenium WebDriver scripts’ Stack Trace to your Email Id | Abode QA

  4. Pingback: Unexpected error launching Internet Explorer. Protected Mode must be set to the same value | Abode QA

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>