ElementNotVisibleException Exception thrown when element is clearly visible (Firefox & IE)

17,558 views
Skip to first unread message

Jakes

unread,
Sep 14, 2012, 1:08:55 PM9/14/12
to webd...@googlegroups.com

This seems so simple but I do not what I am missing.. I am trying to automating a login page webpage but I am getting ElementNotVisibleException exception when trying to click or sendKeys on the user email text field in the login page. 

Can some one please thinking of any reason on why the elementnotvisible exception is thrown. I am using Selenium Webdriver 2.25.

IE version of Java code
====================
WebDriver driver = new InternetExplorerDriver();
WebElement e = driver.findElement(By.id("emailInput"));
e.click();


Firefox Version of Java code
====================
FirefoxProfile profile = new FirefoxProfile();
profile.setEnableNativeEvents(true);
FirefoxDriver driver = new FirefoxDriver(profile);
WebElement e = driver.findElement(By.id("emailInput"));
e.click();


Exception stack from IE
==========
Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: Cannot click on element (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 252 milliseconds
Build info: version: '2.25.0', revision: '17482', time: '2012-07-18 22:18:01'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_06'
Driver info: driver.version: RemoteWebDriver
Session ID: bb44c2e9-d9c0-4826-8b4c-28b551b9be2a
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:188)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:498)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:244)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:77)
at scripts.EnterRunKeeper.main(EnterRunKeeper.java:25)

Peter Gale

unread,
Sep 14, 2012, 1:12:16 PM9/14/12
to webd...@googlegroups.com
Browsers sometimes display elements even though there is something in the html marking them as invisible.

Check your html to see if a parent element is marked as invisible in some way, or post it here for further help.


Date: Fri, 14 Sep 2012 10:08:55 -0700
From: jrag...@gmail.com
To: webd...@googlegroups.com
Subject: [webdriver] ElementNotVisibleException Exception thrown when element is clearly visible (Firefox & IE)
--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/Rn7GxOkPARwJ.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.

Jakes

unread,
Sep 14, 2012, 1:51:00 PM9/14/12
to webd...@googlegroups.com
Nope.. I can't see it's parent marked as hidden in html

 <form name="newSignupForm" class="signUpOrLogInWidget" id="newSignupForm" action="/signup" method="post">
      
                        <input name="_eventName" type="hidden" value="signup" />
                        <input name="support" type="hidden" value="" /> 
                        <input name="return_to" type="hidden" value="" /> 
                        <input name="timestamp" type="hidden" value="" /> 
                        <input name="redirectUrl" type="hidden" value="/login" />
                        <input name="failUrl" type="hidden" value="/login" />
                        <input name="healthyUrl" type="hidden" value=" " />
                        <input name="healthyObjectId" type="hidden" value=" " />
                        <input name="healthyButtonType" type="hidden" value=" " />
                        <input name="healthyOrigin" type="hidden" value="" />
                        <input name="newSignupFormSubmit" style="top: -5000px; position: absolute;" type="submit" value="Submit Query" />
                        <label id="fullNameLabel" for="fullName">Full Name:</label> 
                        <input name="fullName" class="top" id="fullNameInput" type="text" />
                        <label id="emailLabel" for="email">Email:</label> 
                        <input name="email" class="top" id="emailInput" type="text" />
                        <label id="passwordLabel" for="password">Password:</label> 
                        <input name="password" class="passwordPlaceholder" id="passwordInput" type="password" maxLength="128" />
                        
      <div class="btn-container button blue">
       <input name="submit" class="button blue" id="signupSubmit" type="submit" value="Sign Up" />
       <div class="buttonBorder" style="width: 92px; height: 38px;"></div>
       <div class="rkicon"></div>
      </div>
      
                     
      <div style="display: none;">
       <input name="_sourcePage" type="hidden" value="c-5-3S2FR0chDPPG9Ey7a-SG6iao7_J-" /><input name="__fp" type="hidden" value="9uILeSadgSw=" />
      </div>
     </form>

Peter Gale

unread,
Sep 14, 2012, 1:54:28 PM9/14/12
to webd...@googlegroups.com
Is that the full html? ... it could be any parent element, not just the immediate one.


Date: Fri, 14 Sep 2012 10:51:00 -0700
From: jrag...@gmail.com
To: webd...@googlegroups.com
Subject: Re: [webdriver] ElementNotVisibleException Exception thrown when element is clearly visible (Firefox & IE)
To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/co11-iR1cUcJ.

Jakes

unread,
Sep 14, 2012, 5:54:09 PM9/14/12
to webd...@googlegroups.com
I don't like to put the entire HTML page out in this form.

This is public wedpage URL http://runkeeper.com/login


Thanks,
Jakes

Mike Riley

unread,
Sep 14, 2012, 7:22:52 PM9/14/12
to webd...@googlegroups.com
Might it be a timing issue?  Maybe IE is a bit slower than Firefox and it is invisible when your code tries to access it in IE.

See if you can wait until it is visible and if that lets it work.

Mike

Jakes

unread,
Sep 14, 2012, 7:48:16 PM9/14/12
to webd...@googlegroups.com
Not really I added sleep almost 5 to 10 secs just to be sure.. I am still facing the same problem of element not visible both in IE and firefox.

Just to reiterate this failing both in Firefox and IE.

It's only 3 lines of code...

Can some one try it on there end?

InternetExplorerDriver driver = new InternetExplorerDriver();
//driver.setJavascriptEnabled(true);
WebElement e = driver.findElement(By.id("emailInput"));
e.sendKeys("runkee...@outlook.com");

Jakes

unread,
Sep 14, 2012, 8:13:01 PM9/14/12
to webd...@googlegroups.com
I figured out what's the problem I had 2 elements with same id. one was hidden and other was visible. The hidden one was coming up first when searching. 


On Friday, September 14, 2012 4:48:16 PM UTC-7, Jakes wrote:
Not really I added sleep almost 5 to 10 secs just to be sure.. I am still facing the same problem of element not visible both in IE and firefox.

Just to reiterate this failing both in Firefox and IE.

It's only 3 lines of code...

Can some one try it on there end?

InternetExplorerDriver driver = new InternetExplorerDriver();
//driver.setJavascriptEnabled(true);
WebElement e = driver.findElement(By.id("emailInput"));
e.sendKeys("runkeeperql1@outlook.com");

Mike Riley

unread,
Sep 15, 2012, 5:04:08 PM9/15/12
to webd...@googlegroups.com
Gotta keep those IDs unique!  It'll bite you in the butt otherwise.

Glad you figured it out.

Mike


On Friday, September 14, 2012 5:13:01 PM UTC-7, Jakes wrote:
I figured out what's the problem I had 2 elements with same id. one was hidden and other was visible. The hidden one was coming up first when searching. 


On Friday, September 14, 2012 4:48:16 PM UTC-7, Jakes wrote:
Not really I added sleep almost 5 to 10 secs just to be sure.. I am still facing the same problem of element not visible both in IE and firefox.

Just to reiterate this failing both in Firefox and IE.

It's only 3 lines of code...

Can some one try it on there end?

InternetExplorerDriver driver = new InternetExplorerDriver();
//driver.setJavascriptEnabled(true);
WebElement e = driver.findElement(By.id("emailInput"));
e.sendKeys("runkee...@outlook.com");

Anand

unread,
Dec 11, 2012, 8:55:32 PM12/11/12
to webd...@googlegroups.com
I have a similar kind of situation :
I am using FF 12.0, Selenium : 2.26.0, win 7

I want to click the element which becomes visible only after I hover my mouse over some other element. 
So in the code, I first hover over the element, I can see the element to be clicked becomes visible in firefox window but still the click action gives me ElementNotVisibleException. I wonder why. 
i hover over the element by this : 
public void mouseOverElement(By locator)
{
Actions builder = new Actions(driver);

builder.moveToElement(driver.findElement(locator));
//builder.perform();
builder.build().perform();
System.out.println("Hovering on the element !");
}

Then I wait till the desired element becomes visible. and then click on it. 

When I printed the isDisplayed value before and after the hover, it gave correct results as False and True respectively. 
Still, it is not clicking the element. I also checked my cssSelector and there is no other element with the same selector. So now, I am out of options and don't know why it is not working. 

I am using FF 12.0 for a reason and I don't want to use latest FF version. Also, selenium 2.26.0 was released after FF 12.0 did, so there should not be any problem either. 

Anybody have any idea ?

Mike Riley

unread,
Dec 12, 2012, 2:52:49 AM12/12/12
to webd...@googlegroups.com
It sounds like you did everything right, but try this to double check your CSS selector.  Do a findElements() and see if you get a list of more than one, just to be sure you didn't miss another one that matches it somewhere in your page.

If that doesn't show a duplicate, can you share your HTML and Selenium code so we can look at it?

One trick I have used is to single step through the test code while having Firebug up on the browser under test.  It allows you to see what the HTML for the page looks like as it changes.  Be careful though, because if you wait too long with the program halted the connection for Selenium will time out and be closed by the remote server (if you are using a remote server).

Mike

Anand

unread,
Dec 14, 2012, 11:18:28 PM12/14/12
to webd...@googlegroups.com
Hi Mike,
I checked with findElements() and confirmed that there is not more than one elements that are matching same path. I also put explicit wait as you suggested. But no success....

Here's my html : 
<table class="grid">
 <thead>
  <tbody>
   <tr>
     <td class="grid-name">
       <div class="item">
         <div class="someClass1">
            <div class="item-icon item-tight"></div>
            <div class="item-description">
               <h3 class="item-title"><a href="someURL">xyz</a> </h3>
            </div>
        </div>
      </div>
     </td>
     <td class="grid-default"> <span class='' href="#">&nbsp;</span></td>
     <td class="grid-type">abcd</td>
     <td class="grid-last-updated">12/12/2012 4:47:29 PM</td>
     <td class="grid-hidden">
        <div class="item">
           <ul class="item-edit">
               <li><a id="ctl00_ctrl0_lnkDefault" class="" href="someFunction1"><span>Use as default</span></a></li>
               <li><a href="someURL"><span>Edit</span></a></li>
               <li><a id="ctl00_ctrl0_lnkDelete" class="" href="someFunction2"><span>Delete</span></a></li>
           </ul>
        </div>
     </td>
    </tr>
  </tbody>
  <tbody>
  </tbody>
  <tbody>
  </tbody>
  <tbody>
  </tbody>
 </thead>
</table>


and my code is : 

//This is where i move my mouse to...
moveToElement = driver.findElement(By.cssSelector("table.grid > tbody:nth-of-type(1) td.grid-name a"));

//this is the button that appears only after mouse hover over above element. I want to click this. 
WebElement deleteButton = findElement(By.cssSelector("table.grid > tbody:nth-of-type(1) td.grid-hidden a[id$='Delete']"));

//This returns false
System.out.println("before Displayed?:" + deleteButton.isDisplayed());

//Hovering on the element...
Actions builder = new Actions(driver);
builder.moveToElement(driver.findElement(locator));
//builder.perform();
builder.build().perform();
System.out.println("Hovering on the element !");

//This returns true
System.out.println("after Displayed?:" + deleteButton.isDisplayed());

//Getting exception here that element is not visible. I have tried using explicit waits till this gets visible. I have also tried putting Thread.sleep(3000) before clicking. nothing worked.
deleteButton.click();


This code works perfectly fine in chrome and it used to work in earlier versions of FF (i tried on 3.6). Now, I have updated my FF to 17.x and I am using selenium 2.25 but still getting issue.

Mike Riley

unread,
Dec 17, 2012, 4:44:43 PM12/17/12
to webd...@googlegroups.com
I did mistype there and should have said implicit wait:
http://seleniumhq.org/docs/04_webdriver_advanced.html#explicit-and-implicit-waits

I plead jet lag, because I had just flown to Taiwan the day before...  :)

If you are using FF 17 you have to use Selenium 2.27 or native events won't work correctly.

I wonder if bug 2067 is still causing a problem.  I implemented the JavaScript workaround for that and still have it in my library.  Note the commented out code that would be used if 2067 is fixed.  Also, in my case all items I had to hover over were XPath, so I always use an XPath string:

    /**
     * This will do a selenium.mouseOver(hoverLocator) to place the mouse over
     * an element on the web page that makes another element become visible. It
     * will then wait <i><b>timeout</b></i> seconds for the element described by
     * waitLocator to become visible. If it does not then an exception will be
     * thrown showing what we were waiting for never became visible. The
     * hoverLocator <b>must</b> be an XPath locator for the element.<br/><br/>
     * <B>Note: this does a waitForElementPresent(hoverLocator, timeout) to be
     * sure that the element we want to hover over is present, also.</B>
     * @param hoverLocator The locator for the element to hover the mouse over.
     * @param waitLocator  The locator that is currently invisible that we need
     *                     to wait until it is visible.
     * @param timeout      Time in milliseconds to wait before reporting element
     *                     did not become visible by throwing an exception.
     * @throws Exception A Selenium exception or a DOTN_Helper one.
     * @see #waitForElementPresent(java.lang.String, int)
     * @see #waitUntilVisible(java.lang.String, int)
     * @see DefaultSelenium#mouseOver(java.lang.String)
     */
    public void mouseOverAndWait(String hoverLocator, String waitLocator,
                                 int timeout) throws Exception
    {
        waitForElementPresent(hoverLocator, timeout);
        /*
         * This is the WebDriver way, but requires a By class method be used,
         * which is why we require that it must be an XPath locator, but it
         * sometimes fails because of issue 2067:
         * http://code.google.com/p/selenium/issues/detail?id=2067
         */
        //Actions userAction = new Actions(driver);
        //
        //if (hoverLocator.charAt(0) != '.' && hoverLocator.charAt(0) != '/')
        //    throw new Exception(
        //            "The hoverLocator string is not an XPath locator.");
        //
        //WebElement element = waitForElementPresent(By.xpath(hoverLocator),
        //                                           timeout);   // Wait for the hover element
        //userAction.moveToElement(element).perform();
        //waitUntilVisible(element, timeout);
        /*
         * Code from issue 2067, comment #60 (which will work better for us than
         * #57): http://code.google.com/p/selenium/issues/detail?id=2067
         */
        JavascriptExecutor js = (JavascriptExecutor) driver;
        String mouseOverScript =
                "if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('mouseover', true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject) { arguments[0].fireEvent('onmouseover');}";

        if (hoverLocator.charAt(0) != '.' && hoverLocator.charAt(0) != '/')
            throw new Exception(
                    "The hoverLocator string is not an XPath locator.");

        WebElement element = waitForElementPresent(By.xpath(hoverLocator),
                                                   timeout);   // Wait for the hover element
        js.executeScript(mouseOverScript, element);
        waitUntilVisible(waitLocator, timeout);
    }   // mouseOverAndWait(String hoverLocator, String waitLocator)

Mike

Anand

unread,
Dec 17, 2012, 8:57:34 PM12/17/12
to webd...@googlegroups.com
Ok I updated to selenium-server-standalone-2.28.0.jar
Now on FF, my mouse pointer has to be in working window. and on chrome, it has to be out of working window. Then only it works  ;(
This is frustrating.
One more thing, I am instantiating my drivers as just new FirefoxDriver() and new ChromeDriver();
Do I need to call different constructors  ?

Andrew Fowler

unread,
Dec 18, 2012, 9:07:25 AM12/18/12
to webd...@googlegroups.com
I've written a very basic firefox addon that helps with this

http://pasteboard.co/1ENU8J9z.png

The red X next to the id reference signifies it's not unique.

It's designed to be used with my support library, but I can try & create a more standard version over the xmas break if I get chance.

There's an old version here https://addons.mozilla.org/en-us/firefox/addon/nbs-webdriver-api-element-l/ that may (or may not :) ) help in the meantime.

On Saturday, September 15, 2012 1:13:01 AM UTC+1, Jakes wrote:
I figured out what's the problem I had 2 elements with same id. one was hidden and other was visible. The hidden one was coming up first when searching. 


On Friday, September 14, 2012 4:48:16 PM UTC-7, Jakes wrote:
Not really I added sleep almost 5 to 10 secs just to be sure.. I am still facing the same problem of element not visible both in IE and firefox.

Just to reiterate this failing both in Firefox and IE.

It's only 3 lines of code...

Can some one try it on there end?

InternetExplorerDriver driver = new InternetExplorerDriver();
//driver.setJavascriptEnabled(true);
WebElement e = driver.findElement(By.id("emailInput"));
e.sendKeys("runkee...@outlook.com");

Abhinav M

unread,
Mar 6, 2015, 2:41:56 PM3/6/15
to webd...@googlegroups.com
Hi,I am facing similar issue. I can see the text box visible but throwing org.openqa.selenium.ElementNotVisibleException . It works fine with Mozilla firefox.
IE version -8
IEDriver-IEDriverServer_x64_2.44.0

Uday Reddy

unread,
Mar 11, 2015, 9:59:23 AM3/11/15
to webd...@googlegroups.com
Hi Anand,

up to what you have mentioned that is good..but  I want to click on "builder.moveToElement(driver.
findElement(locator));"

How I have to proceed?


Uday Reddy

unread,
Mar 11, 2015, 10:29:29 AM3/11/15
to webd...@googlegroups.com

I have below code with me

Actions actionname = new Actions(wd);
        actionname.moveToElement(wd.findElement(By.xpath(".//*[@id='w2']/div[1]/div/div/div/div/div/div[2]")));
        //builder.perform();
        actionname.build().perform();

        System.out.println("Hovering on the element !");
 
I can able to print "Hovering on the element!" in console also.

how to click on  element..
Reply all
Reply to author
Forward
0 new messages