selectByVisibleText throwing element is not currently visible exception in 2.0b3 FF 3.6.13

1,406 views
Skip to first unread message

jonm42

unread,
Jun 2, 2011, 5:41:11 PM6/2/11
to webdriver
I'm on the migration path from 2.0b1 -> 2.0b3 -> 2.0rc1. Code that
worked fine in 2.0b1 is having the above problem in b3 when it tries
option.setSelected() in Select.java (as shown below). Code in question
looks like:

public void selectByLabel(String locator, String label) {
locator = locator.startsWith("//") ? locator :
String.format("//*[contains(@id,'%s')]", locator);
Select selector = new
Select(driver.findElement(By.xpath(locator)));
selector.selectByVisibleText(label);
}

which ends up with the following traceback:

org.openqa.selenium.ElementNotVisibleException: Element is not
currently visible and so may not be interacted with
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version:
'10.6.7', java.version: '1.6.0_24'
Driver info: driver.version: RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:
39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:
27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at
org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:
131)
at
org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:
105)
at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:
409)
at
org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:
197)
at
org.openqa.selenium.remote.RemoteWebElement.setSelected(RemoteWebElement.java:
99)
--> at
org.openqa.selenium.support.ui.Select.selectByVisibleText(Select.java:
114)
at
com.yesmail.enterprise.pages.PageProxy.selectByLabel(PageProxy.java:
251)
at
com.yesmail.enterprise.pages.AdminToolsPageProxy.setMaxHardBounces(AdminToolsPageProxy.java:
197)
at
com.yesmail.enterprise.AdminDeliveryTest.testConsecutiveHardBounceVisibilityAndDefault(AdminDeliveryTest.java:
63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at org.junit.runners.model.FrameworkMethod
$1.runReflectiveCall(FrameworkMethod.java:44)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:
15)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:
41)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:
20)
at com.yesmail.enterprise.testutils.SeleniumJUnitRunner
$1.evaluate(SeleniumJUnitRunner.java:49)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:
28)
at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:
31)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:
76)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:
50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:
62)
Caused by: org.openqa.selenium.remote.ErrorHandler
$UnknownServerException: Element is not currently visible and so may
not be interacted with
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version:
'10.6.7', java.version: '1.6.0_24'
Driver info: driver.version: unknown

Help greatly appreciated!
Thanks.

Jonathan

Luke Inman-Semerau

unread,
Jun 2, 2011, 6:13:46 PM6/2/11
to webd...@googlegroups.com
In between those versions they added some checks to see if the elements were visible (your error: "Element is not currently visible and so may not be interacted with"). Can you check that that element does not have the following styles (or effective/computed styles ~ use chrome or firebug to check) - opacity:0, height or width 0, display: none, visibility: hidden.

I think in rc2 (rc1 had some IE issues so a new one was released today) that they don't check for opacity or visibility anymore.


--
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.


jonm42

unread,
Jun 3, 2011, 11:48:39 AM6/3/11
to webdriver
It has opacity:0. Will check in RC2 when I get a chance (and when it's
propagated to MVN :) ).

Luke Inman-Semerau

unread,
Jun 3, 2011, 11:57:23 AM6/3/11
to webd...@googlegroups.com

jonm42

unread,
Jun 3, 2011, 12:20:00 PM6/3/11
to webdriver
Still dies with same traceback in RC2. Note that it also dies when
using selectByValue(). This is not good. As an additional data point,
we are using GWT 2.3.

Luke Inman-Semerau

unread,
Jun 3, 2011, 12:45:12 PM6/3/11
to webd...@googlegroups.com
Can you share a link or a reproducible snippet of html?

jonm42

unread,
Jun 3, 2011, 1:08:48 PM6/3/11
to webdriver
Best I can provide is the following; if someone can wrap this into a
GWT generated page, and confirm it has opacity:0, then you have it...

<select class="gwt-ListBox" id="gwt-debug-maxHardBounces">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>

Luke Inman-Semerau

unread,
Jun 4, 2011, 3:33:36 PM6/4/11
to webd...@googlegroups.com
Can you "save page as..." (strip out anything you feel is confidential/privileged/proprietary) and send it? I'm not running gwt.

jonm42

unread,
Jun 6, 2011, 10:14:23 AM6/6/11
to webdriver
I'll see what I can do.

jonm42

unread,
Jun 7, 2011, 1:08:11 PM6/7/11
to webdriver
Our entire application is one mondo web page so there is no easy way
to strip it out. I believe what you mentioned earlier re: opacity:0 is
the key to this. Can we start from there?
> > > > > For more options, visit this group at...
>
> read more »

Luke Inman-Semerau

unread,
Jun 7, 2011, 2:29:55 PM6/7/11
to webd...@googlegroups.com
So, it does check for opacity when selecting elements in a drop down (does not check for it when clicking on an element). How I came about that is below the proposed solutions.

The first question I have to ask is... how do end users interact with this element? If it is invisible is the UI masking it with other elements that are visible that you can .click() on?

I guess there's a couple of things you can do to work-around this. 1) click on the elements displayed in the UI 2) use javascript to set the dropdown yourself  3) change the style of the element to not have opacity 0
A way to do #2:
((JavascriptExecutor) driver).executeScript("for(var i=0; i < arguments[0].options.length; i++){ if (arguments[0].options[i].innerText==arguments[1]){arguments[0].options[i].selected=true;break;}", driver.findElement(By.xpath(locator)), label);

A way to do #3:
((JavascriptExecutor) driver).executeScript("var s=document.createElement('style');s.innerText='select,option{opacity:100 !important;}';document.body.appnedChild(s);");

(you're on your own to try #1)




http://code.google.com/p/selenium/source/browse/tags/selenium-2.0-rc-2/javascript/atoms/dom.js#414

This is the code that is run that determines if an element is visible... from what you are saying if you grab the select element it will check:

(line 476) visibility!= 'hidden'
(line 483-490) elem or any parent element, dispaly != 'none'
(line 495) opacity is checked, opt_ignoreOpacity is set to false from calling method (http://code.google.com/p/selenium/source/browse/tags/selenium-2.0-rc-2/javascript/atoms/action.js#61)
(line 500-593) check that height and width  are both > 0

So, your element is matching one of those conditions. Extra conditions apply if your WebElement is one of the following tags: title, option, optgroup, map, area, input

The extra for the option is just that the select is also 'visible'.

jonm42

unread,
Jun 7, 2011, 3:58:10 PM6/7/11
to webdriver
Firstly, thanks for such a detailed reply and the research needed!
This is just a standard dropdown; the user would click on it to make
options visible, then select what they wanted from the presented
option set. The code I gave above as an example is the actual excerpt.
The thing that bothers me is that this worked all the way back to
2.0a1. Code hasn't changed for some time. I will walk though the code
you mentioned, and confirm/deny the various and sundry conditions. We
are currently in a crunch, so I don't know when I will get a chance to
look at this in the detail I'd like to.

On Jun 7, 11:29 am, Luke Inman-Semerau <luke.seme...@gmail.com> wrote:
> So, it does check for opacity when selecting elements in a drop down (does
> not check for it when clicking on an element). How I came about that is
> below the proposed solutions.
>
> The first question I have to ask is... how do end users interact with this
> element? If it is invisible is the UI masking it with other elements that
> are visible that you can .click() on?
>
> I guess there's a couple of things you can do to work-around this. 1) click
> on the elements displayed in the UI 2) use javascript to set the dropdown
> yourself  3) change the style of the element to not have opacity 0
> A way to do #2:
> ((JavascriptExecutor) driver).executeScript("for(var i=0; i <
> arguments[0].options.length; i++){ if
> (arguments[0].options[i].innerText==arguments[1]){arguments[0].options[i].s elected=true;break;}",
> driver.findElement(By.xpath(locator)),
> label);
>
> A way to do #3:
> ((JavascriptExecutor) driver).executeScript("var
> s=document.createElement('style');s.innerText='select,option{opacity:100
> !important;}';document.body.appnedChild(s);");
>
> (you're on your own to try #1)
>
> http://code.google.com/p/selenium/source/browse/tags/selenium-2.0-rc-...
>
> This is the code that is run that determines if an element is visible...
> from what you are saying if you grab the select element it will check:
>
> (line 476) visibility!= 'hidden'
> (line 483-490) elem or any parent element, dispaly != 'none'
> (line 495) opacity is checked, opt_ignoreOpacity is set to false from
> calling method (http://code.google.com/p/selenium/source/browse/tags/selenium-2.0-rc-...
> )
> ...
>
> read more »

jonm42

unread,
Jun 8, 2011, 2:20:40 PM6/8/11
to webdriver
Ok. I've carved out some time. So if I understand this correctly,
something very odd is happening here. I will lay out the call flow and
some observations; see if it makes sense.

notation: <script>@<lineNumber> in the 2.0-rc-2 tag

1) we start in webdriver java code that calls setSelected
(bot.action.setSelected(action.js@221)) on an option element
2) action.js@224 calls bot.action.checkShown_ which calls
bot.action.isShown_ which calls bot.dom.isShown (dom.js@414) with
ignoreOpacity == true (action.js@50)
3) to be continued -- something just came up.
> > > > > > > > > > > >        at...
>
> read more »

jonm42

unread,
Jun 16, 2011, 12:31:16 PM6/16/11
to webdriver
Got a few more cycles to work on this -- I tried implementing option
2, with no luck; the code ended up looking like this:

public void selectByLabel(String locator, String label) {
locator = locator.startsWith("//") ? locator :
String.format("//*[contains(@id,'%s')]", locator);
((JavascriptExecutor) driver).executeScript(
"for(var i=0; i < arguments[0].options.length; i++) {"
+
" if
(arguments[0].options[i].innerText==arguments[1]) {" +
"arguments[0].options[i].selected=true;" +
"break;" +
"}" +
"}",
driver.findElement(By.xpath(locator)), label);
// Select selector = new
Select(driver.findElement(By.xpath(locator)));
// selector.selectByValue(label);
// selector.selectByVisibleText(label);
}

but the selected value didn't change and the downstream assert then
failed. Per firebug, the computed style of the select ended up looking
like the following, which looks like it should work. I'm at a loss as
to how to move forward and any additional help would be deeply
appreciated.

Text
font-family Arial,Geneva,sans-serif
font-size 11px
font-weight 400
font-style normal
color #000000
text-transform none
text-decoration none
letter-spacing normal
word-spacing 0
line-height 13.3667px
text-align start
vertical-align baseline
direction ltr
Background
background-color #F9F9F9
background-image none
background-repeat repeat
background-position 0 0
background-attachment scroll
opacity 0
Box Model
width 48.4833px
height 18px
top 0
right -2.48333px
bottom 0
left 0
margin-top 0
margin-right 0
margin-bottom 0
margin-left 0
padding-top 0
padding-right 0
padding-bottom 0
padding-left 0
border-top-width 2px
border-right-width 2px
border-bottom-width 2px
border-left-width 2px
border-top-color #F0F0F0
border-right-color #F0F0F0
border-bottom-color #F0F0F0
border-left-color #F0F0F0
border-top-style inset
border-right-style inset
border-bottom-style inset
border-left-style inset
Layout
position absolute
display block
visibility visible
z-index auto
overflow-x -moz-hidden-unscrollable
overflow-y -moz-hidden-unscrollable
white-space nowrap
clip auto
float none
clear none
-moz-box-sizing border-box
Other
cursor default
list-style-image none
list-style-position outside
list-style-type disc
marker-offset auto
> > > > > > > > > > > > >        at...
>
> read more »

jonm42

unread,
Jun 16, 2011, 12:38:48 PM6/16/11
to webdriver
Aha! If I set the opacity to 100 (via firebug), then it works just
fine. So it looks like there's a problem with not checking for opacity
of options within a select. How do we proceed from here?
> > > > > > > > > > > > > > looks like:...
>
> read more »

Luke Inman-Semerau

unread,
Jun 16, 2011, 12:57:48 PM6/16/11
to webd...@googlegroups.com
Try setting it in the test:

WebElement select = driver.findElement(By.xpath(locator));
((JavascriptExecutor)driver).executeScript("arguments[0].style.opacity = 100;", select);
(new Select(select)).selectByVisibleText(label);

>
> read more »

jonm42

unread,
Jun 16, 2011, 1:09:44 PM6/16/11
to webdriver
That works! A 10^6 thank you's. So it this a bug? An artifact of using
GWT? Alpha particles?
> ...
>
> read more »

Luke Inman-Semerau

unread,
Jun 16, 2011, 2:43:41 PM6/16/11
to webd...@googlegroups.com
Not a bug. The select you are setting here is not actually visible to the user (something else that may look like one actually is). If you were to truly emulate end user's interactions you'll have to change the code to click on certain other elements that are masking the select. Since I never saw the html I have no idea which elements they may be. So, essentially an artifact of using GWT... 

and you're welcome :) Glad to have figured it out... even if it did take 10^6 emails to do so ;)

> ...
>
> read more »

Reply all
Reply to author
Forward
0 new messages