How to find an element in a popup window using WebDriver/Java?

1,878 views
Skip to first unread message

carina0110

unread,
Oct 14, 2011, 2:39:43 AM10/14/11
to Selenium Users
I have tried every thing reasonable and unreasonable and just can't
figure this out.

I have an app that, after make a menu selection, a window open for
user input. I have the id of the element, which is several layers down
into the html code. I was able to recognize one of the outer frames
(there are 2 or 3 iframe levels, as far as I can see, but WebDriver
just can't find the element.

I can see it in the code but somewhere higher up in the code, between
two divs, WebDriver can't find any elements in the popup.

The question is: how can I search for all elements in that window,
regardless of how many frames are there???

There has to be an easier way to identify elements and their correct
frames.

Thanks.

gouse basha

unread,
Oct 14, 2011, 2:55:49 AM10/14/11
to seleniu...@googlegroups.com
It is better to try with By.link instead with id


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.


Mark Collin

unread,
Oct 14, 2011, 4:02:00 AM10/14/11
to seleniu...@googlegroups.com
To find element within an iFrame you need to switch to it. If you have
multiple levels of iFrame you will need to switch multiple times.

Thanks.

--


You received this message because you are subscribed to the Google Groups
"Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to
selenium-user...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/selenium-users?hl=en.


--
This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.

If you have received this email in error please notify postm...@ardescosolutions.com

carina0110

unread,
Oct 14, 2011, 8:49:10 AM10/14/11
to Selenium Users
I did. I have switch to each frame and WebDriver still can't see it.
In a desperate attempt, I decided to start from the highest point in
the code where I can see the popup window selected when I do "inspect
element". From that point, I did a findElement for every single div I
find on my long way down the code to the element I want. However,
after 5 or 6 divs down the hierarchy, WebDriver can't see the next div
and the game is over for me (and I'm still many divs away from the
element I need) and I don't see any thing particularly different
between the last visible div and the next div that WebDriver can't
see.

Selenium IDE can see it quickly but it's showing frames like w20, w21,
etc. that I don't see in the html code. But if Selenium IDE could find
it, then WebDriver should too. I must say, WebDriver has turned out to
be such an expensive proposition for us.
> For more options, visit this group athttp://groups.google.com/group/selenium-users?hl=en.
>
> --
> This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.
>
> If you have received this email in error please notify postmas...@ardescosolutions.com- Hide quoted text -
>
> - Show quoted text -

Mark Collin

unread,
Oct 14, 2011, 9:07:44 AM10/14/11
to seleniu...@googlegroups.com
When I say switch to an iFrame I mean use the "selenium.selectFrame()"
command, or if you are using webdriver the "driver.switchTo().frame()"
command.

If you have received this email in error please notify postm...@ardescosolutions.com

carina0110

unread,
Oct 14, 2011, 9:16:12 AM10/14/11
to Selenium Users
The elements I need are not links, they are input fields.

thanks.

On Oct 14, 2:55 am, gouse basha <mohammedg...@gmail.com> wrote:
> It is better to try with By.link instead with id
>
> >http://groups.google.com/group/selenium-users?hl=en.- Hide quoted text -

carina0110

unread,
Oct 14, 2011, 9:50:50 AM10/14/11
to Selenium Users
I have done that I have switch to each an every single frame I see in
the code, in the order I see it in the code. In addition, after I
switch to a frame, I tried to get all them frames in the window, which
comes back with null. I have also gone back to wherever
driver.switchTo().defaultContent() takes and tried to start the frames
navigation from there. I also tried by window handle. I tried finding
the element by xpath, by name by id. Tried alert too.

Thanks
> For more options, visit this group athttp://groups.google.com/group/selenium-users?hl=en.

Mark Collin

unread,
Oct 14, 2011, 9:58:17 AM10/14/11
to seleniu...@googlegroups.com
Can you provide your script and the page markup ?

Thanks

If you have received this email in error please notify postm...@ardescosolutions.com

carina0110

unread,
Oct 14, 2011, 12:17:40 PM10/14/11
to Selenium Users
Thanks, Mark. I found the frames I needed and figure out when to use
them. I must have some other 'switchTo.frame' before that cause the
problem. Still, this is such a painful process. Here's what I do to
find a new frame(s). Is there a better way?

1. I inspect the element
2. I go up the html code until I find an iframe tag
3. I hover over it to see if that frame looks like the right one, if
not
4. I keep going up the html code to find the next iframe up
5. I hover again and inspect that frame. I keep doing this until the
next frame or element no longer highlights in the window I want to
work with
6. Then, I start doing switchTo().frame()'s in the reverse order all
the way up to the element I want to work with.
7. If it doesn't work, I start removing frames from the top or the
bottom of my list (it's a toss-up at this point)

Is there a more reasonable approach?

Thanks
> For more options, visit this group athttp://groups.google.com/group/selenium-users?hl=en.

Mark Collin

unread,
Oct 17, 2011, 4:28:03 AM10/17/11
to seleniu...@googlegroups.com
I normally do it in reverse (i.e. start at the top of the document and
scroll down looking for iFrames, but it's is basically exactly the same
process as what you are doing). Unfortunatly there is no easy way to deal
with iFrames that I'm aware of, I would suggest that they should be used
sparingly as they are a PITA. I would raise a defect on your devs and ask
them to be more sensible with their iFrame usage, it should really be a last
resort and I would expect them to be using some sort of server side
technology (.NET, ASP, PHP, GROOVY, etc.) to build pages.

Indiscriminate iFrame usage can really screw things up if the from a
bookmark/navigation point of view, and especially if the site targeted by
them changes.

Thanks

--


This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.

If you have received this email in error please notify postm...@ardescosolutions.com

Reply all
Reply to author
Forward
0 new messages