• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • Programming Languages
    • Java Tutorials
    • Python Tutorials
    • JavaScript Tutorials
  • Automation Tools and Different Tools
    • Web Automation
      • Selenium with Java
        • Selenium Basic
        • Selenium Advance
        • Selenium Realtime
        • Framework
        • Selenium Interview
        • Selenium Videos
        • Selenium with Docker
      • Selenium with Python
      • WebdriverIO
        • Selenium Webdriver C# Tutorial
      • Cypress
      • Playwright
    • TestNG
    • Cucumber
    • Mobile Automation
      • Appium
    • API Testing
      • Postman
      • Rest Assured
      • SOAPUI
    • testRigor
    • Katalon
    • TestProject
    • Serenity BDD
    • Gradle- Build Tool
    • RPA-UiPath
    • Protractor
    • Windows Automation
  • Automation For Manual Testers
  • Services
  • Online Training
  • Contact us
  • About me
  • Follow us
    • Linkedin
    • Facebook Group
    • Facebook Page
    • Instagram

Automation

Selenium WebDriver tutorial Step by Step

You are here: Home / Basic Selenium / How to Solve ElementNotVisibleException in Selenium Webdriver

How to Solve ElementNotVisibleException in Selenium Webdriver

April 20, 2015 by Mukesh Otwani 61 Comments

Top 10 inspirational quotes

Hello, Guys, Welcome back to Selenium tutorial, today we will see how to handle element not visible  exception in Webdriver.

I faced this exception number of times, I struggled a lot while searching solution, and finally, I got so many solutions to solve this exception.

Before jumping to ElementNotVisibleException you should check below two posts that actually will help you to understand exception better.

How to handle Exception in Selenium

What are different exception is available in Selenium.

 

Full Exception document is available here- https://selenium.googlecode.com/git/docs/api/py/common/selenium.common.exceptions.html

 

Let us see what the reason behind this exception is:

Reasons for ElementNotVisibleException in Selenium Webdriver

Reason 1- Duplicated XPATH

While writing xpath for your application, you might have taken xpath that is matching with more than 1 element, in this case, Selenium will throw Element, not the visible exception.

If you are new to Selenium and facing issues while writing XPath then please check below post which will help you to write xpath from basic to advance level.

How to write Dynamic Xpath in Selenium Webdriver

Reason 2-

If you are trying to access some particular element on Webpage that is not currently visible, in this case also you will get the Element, not visible exception.

 

 

ElementNotVisible Exception in Selenium
ElementNotVisible Exception in Selenium

Solutions for ElementNotVisibleException in Selenium Webdriver

First Solution: Try to write unique XPATH  that matches with a single element only.

 

Second Solution:

Use Explicit wait feature of Selenium and wait till the element is not visible. Once it is visible then you can perform your operations.

Syntax for Explicit wait

new WebDriverWait(driver, 30).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[text()='index.html']")));

 

Explanation- In above example, Selenium will wait 30 seconds until the element is not visible and once it is visible, Selenium will perform an action and will move on to the next step.

You can also give a try using JavaScript click that forcefully click on Element 

 

Third solution:

This actually works for me a number of times. I was struggling with the OK button in my application. Even I was writing unique xpath but still I was facing Element Not Visible exception.  I have tried below code that solved my issue.

int ok_size=driver.findElements(By.xpath("//button[text()='OK']")).size();

driver.findElements(By.xpath("//button[text()='OK']")).get(ok_size-1).click();

Explanation

First, I have taken the size of the element then in next statement, I took the first element from the list and I clicked on OK Button.

I have seen so many scenarios where I solved my issue using above scenario.

I also faced lots of Hidden Web Elements in my web application and used below trick which helped me a lot.Check out below youtube video for the same.

 

Hope this post is worth for you and your friends as well, so if you find this as useful then do share this post with your friends using sharing buttons.

Comment below if you are facing any issue.

Thanks for visiting my blog. Keep visiting. Have a nice day.

For More updates Learn Automation page

For any query join Selenium group- Selenium Group

Filed Under: Basic Selenium Tagged With: Selenium Exception

Reader Interactions

Comments

  1. Bhargavi says

    July 18, 2022 at 3:26 PM

    Hi, Mukesh

    Thanks for the solution, I have tried all three, Still facing the issue.

    I have been trying to click an element in DOM, The Xpath is showing only 1 Result while Inspecting
    Still facing Element Not found Exception.
    Tried with Js Executor, WebDriverWait. I think the element is overlapped. That’s why its unable to locate the element.

    Please help me to find the ways to locate the element while automating to click it. Thanks

    Reply
    • Mukesh Otwani says

      July 22, 2022 at 1:07 PM

      Hi Bhargavi, JS Click should work even if it is overlapping. Please send me logs and code too mukeshotwani@learn-automation.com

      Reply
  2. Tanushri says

    July 16, 2020 at 5:05 PM

    Hi Mukesh,

    Thanks alot as the third solution solved my problem. I was continuously getting elementNotInteractableException but using ur solve it works fine. 🙂

    Reply
    • Mukesh Otwani says

      July 16, 2020 at 7:26 PM

      Cheers, Tanushri..:)

      Reply
  3. sivaprakash says

    October 3, 2019 at 2:36 PM

    Hi Mukesh,
    Thanks for the third solution. its work for me.
    thanks

    Reply
    • Mukesh Otwani says

      October 3, 2019 at 6:35 PM

      Thats great..:)

      Reply
  4. Tanu says

    July 30, 2019 at 9:50 AM

    Hi Mukesh,

    I am facing an issue while executing a scenario.
    1- There is calendar (Bootstrap is used). As soon as we click on calendar button its opens a calendar and also next and prev arrow to select any month’s date.

    Issue is this. Not able to create the Xpath for next and prev button as element is not visible.

    check this and help: https://demos.telerik.com/kendo-ui/datetimepicker/index

    Reply
    • Mukesh Otwani says

      August 5, 2019 at 12:35 AM

      Hi Tanu,

      First enable calendar control so that calendar should get enabled then use this xpath //a[@aria-label=’Next’] for next month. Similarly use //a[@aria-label=’Previous’] for previous month control.

      Reply
  5. Manikumar says

    April 24, 2019 at 4:22 PM

    Hi When we ran scripts to Intellij scripts were running properly but wehn we trigger with Jenkins we are getting no such element found exception can you please guide us?

    Reply
    • Mukesh Otwani says

      April 25, 2019 at 3:56 PM

      Hi Mani,

      Ideally, it should not fail but if it is failing then based on exception we need to fix the script.

      Reply
    • Mukesh Otwani says

      April 25, 2019 at 4:01 PM

      Hi Manikumar,

      Kindly check whether application websitehas same navigation just like you are having through IntelliJ. Also use proper wait if you are getting issues with element http://learn-automation.com/explicit-wait-in-selenium-webdriver/

      Reply
  6. Anija says

    February 21, 2017 at 3:39 PM

    Thank you so much…….

    Reply
    • Mukesh Otwani says

      February 21, 2017 at 5:31 PM

      Hi Anija,

      I am glad to see your comments. Keep in touch with my blog…:)

      Reply
  7. Lakshmi says

    February 8, 2017 at 3:57 PM

    Hi Mukesh,
    Please tell me the difference between ElementNotVisibleException and ElementNotFoundException?

    Reply
    • Mukesh Otwani says

      February 8, 2017 at 4:30 PM

      Hi Lakshmi,

      As per my knowledge, ElementNotFound is a superclass and its sub classes are NoSuchElementException, NoSuchFrameException, NoSuchWindowExcption etc(there could be more). So ElementNotFoundException can be categorized into other exceptions
      While ElementNotVisibleException happens an element is present on the DOM, but it is not visible, and so is not able to be interacted with. For more details: https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/ElementNotVisibleException.html

      Reply
  8. Vanitha says

    February 1, 2017 at 7:30 AM

    mukesh i have some doubts on selenium. please give me ur mail id

    Reply
    • Mukesh Otwani says

      February 1, 2017 at 3:05 PM

      support@learn-automation.com kindly share your doubts with us.

      Reply
  9. preetam singh says

    January 31, 2017 at 1:11 AM

    Hi Mukesh
    i have one question
    suppose we have three element of same xpath
    then how will we use appropriate element

    Reply
    • Mukesh Otwani says

      January 31, 2017 at 1:31 PM

      Hi Preetam you can use index if multiple element found. http://learn-automation.com/difference-between-findelement-and-findelements-in-selenium-webdriver/

      Reply
      • Preetam Singh says

        January 31, 2017 at 2:41 PM

        thnx Mukesh
        how can i find all broken links from footer section

        Reply
        • Mukesh Otwani says

          January 31, 2017 at 6:16 PM

          Hi Preetam,

          please visit this link http://learn-automation.com/find-broken-links-using-selenium/

          Reply
  10. mayank chincholkar says

    January 8, 2017 at 3:16 PM

    Nice post, helped me a lot!

    Reply
    • Mukesh Otwani says

      January 9, 2017 at 7:27 PM

      Good to hear that mayank 🙂 keep in touch

      Reply
  11. Balakrishna says

    December 1, 2016 at 3:24 PM

    Hi Mukesh,
    http://www.nextrow.com/adobe-experience-manager/
    In the page ,there is button named Request for consultation ,I try to locate the element by using xpath but i am getting exception org.openqa.selenium.ElementNotVisibleException: element not visible

    Reply
    • Mukesh Otwani says

      December 6, 2016 at 12:39 PM

      Hi Bala,

      I can see multiple button for this name so you can check which button to click.

      Reply
      • Balakrishna says

        February 6, 2017 at 7:57 PM

        I have taken xpath by using Selenium IDE to click the First Request Consultation button …but its giving above exception

        Reply
        • Mukesh Otwani says

          February 6, 2017 at 8:25 PM

          Hi Balakrishna,

          Try with this xpath for first one –> //h2[text()=’Services’]/preceding::*[text()=’Request Consultation’]
          and this one for second one –> //h2[text()=’Services’]/following::*[text()=’Request Consultation’]
          I hope these two should work.

          Reply
  12. Nikhil says

    November 25, 2016 at 2:47 PM

    Hi Mukesh,

    In my case I had to apply filters to 3 different columns on a single page of my application. And each first element after filtering had same locator. 🙁

    I was literally trying this for 2 days and finally it worked using 3rd solution .

    Thank you so much worked like a gem even though at first glance it looked like pretty off-beat solution. Cheers!

    Reply
    • Mukesh Otwani says

      November 25, 2016 at 2:52 PM

      Wow Cheers Nikhil.

      Reply
  13. sumit says

    November 10, 2016 at 12:23 AM

    Hi Thanks for the Third Solution. its work for me. i got stuck in this situation for long time. but now its resolve.
    Thanks

    Reply
    • Mukesh Otwani says

      December 14, 2016 at 12:28 AM

      Cheers Sumit.

      Reply
  14. Ricardo says

    November 3, 2016 at 7:35 PM

    I was trying Explicit Wait my way and it wasn’t working. Explicit Wait your way worked for me, thanks!

    Reply
    • Mukesh Otwani says

      November 4, 2016 at 1:12 AM

      Great Ricardo, I am glad it helped you.

      Reply
  15. Amit Chaudhary says

    October 12, 2016 at 4:15 PM

    Hi Mukesh,

    Thanks for the valuable post.

    Third solution work for me number of times but today it is not working for me.

    What is the problem.

    Below is the code-
    WebElement we=driver.findElement(By.xpath(“.//*[@id=’TrackersMenue’]/a”));
    we.click();
    driver.manage().timeouts().implicitlyWait(6, TimeUnit.SECONDS);
    int menu=driver.findElements(By.xpath(“.//*[@id=’exerciseMenuId’]/a/span”)).size();
    driver.findElements(By.xpath(“.//*[@id=’exerciseMenuId’]/a/span”)).get(menu-1).click();

    Reply
    • Mukesh Otwani says

      October 13, 2016 at 8:56 AM

      Hi Amit,

      Try below methods today https://www.youtube.com/watch?v=2eEr0jtmpwE

      Reply
  16. Hemanth Govindu says

    October 9, 2016 at 11:06 PM

    Hi Mukesh,
    I’ve some doubt regarding ElementNotVisibleException, While i’m automating bookmyshow.com, when ever I navigate to home page, it asks for the location to enter at the topmost right corner of the page. I used the unique xpath, still faced ElementNotVisibleException and I didn’t change anything and executed few hours after, it worked fine. Also used implicit wait. could you please clarify my confusion and reason behind the failure?

    Thanks in advance.

    Reply
    • Mukesh Otwani says

      October 9, 2016 at 11:07 PM

      Hi Hemanth,

      I would suggest you to start automating below sample apps.

      http://enterprise.demo.orangehrmlive.com/symfony/web/index.php/auth/login

      Reply
  17. sifat says

    September 3, 2016 at 12:18 PM

    Awesome bro!
    3rd option worked for me.

    Reply
    • Mukesh Otwani says

      September 6, 2016 at 3:51 PM

      Hey Sifat Cheers

      Reply
  18. Anand says

    August 8, 2016 at 7:23 AM

    Third Solutions worked for me. Thank you so much. Was challenging to find your solutions on Google.

    Thanks a ton appreciated

    Thanks
    Anand

    Reply
    • Mukesh Otwani says

      August 18, 2016 at 10:44 PM

      Cheers Anand.

      Reply
  19. Priscilla says

    July 20, 2016 at 11:41 AM

    Hi ,
    Solution No:3 worked perfectly for me. I have tried other solution and banging my head for past 3 days. Got few expert help too but nothing worked out.
    Thanks for the Post

    Reply
    • Mukesh Otwani says

      July 20, 2016 at 1:41 PM

      Cheers Priscilla 🙂 I am glad it worked for you.

      Reply
  20. ashwinishanbhogh says

    March 1, 2016 at 2:05 AM

    Hi, third solution for elementnot visible exception workedout for me..thanks a lot

    Reply
    • Mukesh Otwani says

      March 2, 2016 at 12:00 AM

      Cheers Ashwin 🙂

      Reply
  21. Ashutosh Mishra says

    December 1, 2015 at 10:17 AM

    Hello Mukush..:)
    can we automate QC

    Reply
    • Mukesh Otwani says

      December 1, 2015 at 11:40 AM

      No Ashutosh. Webdriver mainly deals with Web Browsers.

      Reply
  22. sergio pavez says

    November 26, 2015 at 12:29 AM

    Hey, while your solution works (second solution) I still have the same issue when trying to access another dropdown inside the one that I’m waiting. I tried to do the same thing again (new WebDriverWait) but it does not work.

    Here are the lines that I’m using:

    driver.findElement(By.xpath(“.//*[@id=’t3-mainnav’]/div/div/div/div/ul/li[3]”)).click();

    new WebDriverWait(driver, 30).until(ExpectedConditions.visibilityOfElementLocated(By.xpath(“.//*[@id=’t3-mainnav’]/div/div/div/div/ul/li[3]/div/div/div/div/div/ul/li[6]”))).click();

    new WebDriverWait(driver, 30).until(ExpectedConditions.visibilityOfElementLocated(By.xpath(“.//*[@id=’t3-mainnav’]/div/div/div/div/ul/li[3]/div/div/div/div/div/ul/li[6]/div/div/div/div/div/ul/li[2]”))).click();

    Reply
    • Mukesh Otwani says

      November 27, 2015 at 3:16 PM

      Hi Sergio,

      Look like there is some issue with Xpath which you have written try to write xpath with custom methods which may fix this issue.

      Please check below article and try to make the changes and run again

      http://learn-automation.com/how-to-write-dynamic-xpath-in-selenium/

      Reply
  23. Prasad says

    April 20, 2015 at 10:28 AM

    The workaround sounds good, will give a try, thank you for sharing.

    got a doubt the reason 1st reason (Reason 1- Duplicated xpath), if there are duplicate xpath, I believe, selenium will take action on the 1st xpath which will display in html, let me know if my understanding is wrong.

    Reply
    • Mukesh Otwani says

      April 20, 2015 at 11:26 AM

      Hello Prasad,

      Nice observation, In my case when I write xpath and if it matches with more than 1 element, selenium always confuse which element to click and it throws exception.

      As per your comment it will click on first element but I am not sure. You can check from your end.

      Reply
      • srreddy says

        April 20, 2015 at 2:12 PM

        Hi Mukesh,you doing well

        Reply
        • srreddy says

          April 20, 2015 at 2:14 PM

          when to use unregistered webdriver event listener

          Reply
          • Mukesh Otwani says

            April 20, 2015 at 2:35 PM

            For listener I found 1 nice article check below link

            http://www.toolsqa.com/selenium-webdriver/event-listener/

          • srreddy says

            April 22, 2015 at 8:23 PM

            Hi…Mukesh
            1.All Browsers support for File Upload(text,Excel,button)?
            2.Difference between data driven and keyword driven framework

          • srreddy says

            April 22, 2015 at 8:25 PM

            If u dont mind Give me your gmail id, I will send some doubts

        • Mukesh Otwani says

          April 20, 2015 at 2:34 PM

          Thanks Srreddy 🙂

          Reply
          • Gaurav Khurana says

            November 18, 2016 at 11:23 AM

            Good to see Mukesh you are sharing other blogs on your website!!! cheers

          • Mukesh Otwani says

            November 23, 2016 at 3:15 PM

            Thanks Gaurav, I have sent a message to your blog. kindly check.

          • Gaurav Khurana says

            December 1, 2016 at 11:40 AM

            Thanks Mukesh for taking time and sharing your views on the blog.

            Because of your motivation i am able to post a new post after a long time. Hope you like it
            http://udzial.com/extract-text-image/

          • Mukesh Otwani says

            December 6, 2016 at 2:16 PM

            Congrates Gaurav 🙂 Nice post..

Leave a Reply Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Free Selenium Videos

https://www.youtube.com/watch?v=w_iPCT1ETO4

Search topic

Top Posts & Pages

  • Selenium Webdriver tutorial for beginners
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Selenium Webdriver C# Tutorial
  • WHAT ARE YOUR EXPECTATIONS FROM US?

Stay connected via Facebook

Stay connected via Facebook

Archives

Footer

Categories

Recent Post

  • API Testing Using Postman And RestAssured
  • Disable Personalise Your Web Experience Microsoft Edge Prompt In Selenium
  • How To Fix Error: No tests found In Playwright
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Best and easy way to Group test cases in selenium

Top Posts & Pages

  • Selenium Webdriver tutorial for beginners
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Selenium Webdriver C# Tutorial
  • WHAT ARE YOUR EXPECTATIONS FROM US?