1.

What is ElementNotVisibleException?

Answer»

You often get ElementNotVisibleException when you execute selenium scripts when WebDriver locate WEB element on the current webpage but the element is not visible on the screen.

There are many reasons that accumulate for this exception. Below are the reasons for ElementNotVisibleException –

Not locating correctly

  • When your locator is incorrect, selenium WebDriver throws “NoSuchElementException”. Exception means, WebDriver is able to locate elements, but the DESIRED element is not visible.
  • Your locator may be wrong in case of a nested web element. A web element inside web element is called as the nested web element.

Solution:

Locate correct and specific element.

The desired element is overlapped by another web element

  • Many applications nowadays use toaster MESSAGES. A toaster message stays on screen for 3 seconds.
  • When you click on any button or link, you might get the above exception as button or link is overlapped by toast message. Webdriver will not be able to click on button or link and throws a perfect exception stating other elements would receive the click.

Solution:

  • Wait till toast message disappears. You must use the wait property provided by selenium.

Ajax calls

  • AJAX  allows web pages to be UPDATED asynchronously by exchanging data with a web server behind the scenes. It is possible to update parts of a web page without reloading the whole page. Selenium wait when the whole page is loading but can not recognize loading through AJAX calls. If you perform any action on a web element that is still loading because of AJAX calls when AJAX calls in progress, you may get NoSuchElementException or Element is not clickable(If action is click)  or Element is not visible exceptions.

Solution:

  • Wait till the AJAX call is complete by using selenium wait property.

Webdriver is unable to auto-scroll to the desired element

  • If your web page has a vertical scroll bar and you need to perform an action on web element which shows up in the visible area when a user scrolls down. Webdriver mostly scrolls down to element and perform desired OPERATIONS but sometimes, web driver is not able to do so. In this case, you may get an exception.

Solution:

  • Scroll to the element using javascript or Actions class so that the element is visible on the screen.
  • By using selenium wait property.


Discussion

No Comment Found