ElementNotVisibleException: Element is not currently visible and so may not be interacted with

1,590 views
Skip to first unread message

confusa

unread,
Feb 2, 2011, 3:50:45 PM2/2/11
to webdriver
Here is my method to click the element:

public void clickGallery(String show) {
StringBuilder sb = new StringBuilder();
sb.append("//a[starts-with(@href, '/");
sb.append(show);
sb.append("/gallery/')]");
String xpath = sb.toString();
isElementXpathPresent(xpath); // for debugging this returns true
WebElement element = driver.findElement(By.xpath(xpath));
element.click();

And the HTML on the page:
<div class="content-wrapper">
<ul class="menu" style="width: 3000px; position: relative; left:
0px;">
<li>
<div class="gallery">

<div title="title" class="media_thumbnail gallery_thumbnail">
<a href="/show/gallery/more">
</div>
</div>

And the error:
org.openqa.selenium.ElementNotVisibleException: Element is not
currently visible and so may not be interacted with
System info: os.name: 'Linux', os.arch: 'amd64', os.version:
'2.6.32-27-generic', java.version: '1.6.0_22'
Driver info: driver.version: RemoteWebDriver

Now I can run the isElementPresent command and it is there, here is
that method:
protected boolean isElementXpathPresent(String xpath) {
try {
driver.findElement(By.xpath(xpath));
return true; // Success!
} catch (NoSuchElementException ignored) {
return false;
}
}

What am I missing here? Why is the element "not visible"? Now there
are multiple xpaths on the page that would match, but I am assuming it
would just pick the first as this same general method has been
successful in other places.

confusa

unread,
Feb 2, 2011, 6:50:35 PM2/2/11
to webdriver
Even more perplexing is I added this code for debugging:

RenderedWebElement element = (RenderedWebElement)
driver.findElement(By.xpath(xpath));
element.getTagName();
element.getAttribute("href");
element.isDisplayed();

getTag comes back as "a" which is correct.
getAttribute comes back as "/show/gallery/more" which is also correct.
isDisplayed is false...why?!?!

Daniel Wagner-Hall

unread,
Feb 2, 2011, 7:23:54 PM2/2/11
to webdriver
isDisplayed will be false if your element isn't currently thought of
us visible; some reasons for this:
* Width = 0
* Height = 0
* CSS of element or one of its parents sets display or visibility to
a non-displayed value
* Element has been absolutely positioned outside the viewable page
(e.g. at (-5000, -5000))

If you post the whole HTML, CSS and Javascript for the page, someone
can probably tell you more precisely why the element isn't visible.

> --
> You received this message because you are subscribed to the Google Groups "webdriver" group.
> 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.
>
>

DC

unread,
Feb 9, 2011, 12:03:14 AM2/9/11
to webdriver
r u facing the issue in IE only? Sometimes it may happen that the
element is not visible and u need to scroll to the element to make it
visible.
U can try js.executeScript("arguments[0].scrollIntoView(true);",
element); before clicking.

Thanks,
D

Kamal Ahmed

unread,
Oct 2, 2012, 10:53:50 AM10/2/12
to webd...@googlegroups.com
I tried this solution and got exception:

org.openqa.selenium.WebDriverException: TypeError: arguments[0].scrollIntoView is not a function


i am using Webdriver to click on a textbox:


JavascriptLibrary jsLib = new JavascriptLibrary(); 
jsLib.executeScript(getDriver(), "arguments[0].scrollIntoView(true);","addRowTable:0:hostName");
//jsLib.executeScript(driver, script, args) 
getDriver().findElement(By.id("addRowTable:0:hostName")).sendKeys("bbbbbbbb");
the id is generated from primefaces.

Any suggestion ?
Thanks,
-Kamal.
Reply all
Reply to author
Forward
0 new messages