Is there no way to switch driver back to parent frame from the existing child frame ?

4,528 views
Skip to first unread message

Talwinder singh

unread,
Sep 28, 2011, 4:36:32 AM9/28/11
to webdriver

Is there no way to switch driver back to parent frame from the
existing child frame ?

I am trying to create a method which will try to search a specific
frame in the DOM, it will traverse the tree of DOM nodes frame to
frame and search it.

For that i may need to switch back to the parent frame from the
existing child frame. I am not able to get it currentrly , can anyone
help ?

I am using Selenium 2.6 WebDriver .

Thanks in Advance
Talwinder Singh

Krishnan Mahadevan

unread,
Sep 28, 2011, 7:13:07 AM9/28/11
to webd...@googlegroups.com
You could perhaps think of saving the current frame prior to navigating to its child frame.
Would that help ?

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"




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


Daniel Wagner-Hall

unread,
Sep 28, 2011, 8:09:34 AM9/28/11
to webd...@googlegroups.com
driver.switchTo().defaultContent() will take you back to the top level
- you can traverse back down from there if you have many nested
frames.

Talwinder singh

unread,
Sep 30, 2011, 12:09:05 AM9/30/11
to webdriver

Hi Krishnan,

I tried that but there seems limitation on webdriver side that by
using switch method driver can shift only to the frame which are below
the current frame in the tree and not to the frame which is above it,
so even if i store the name of it webdriver throws an error while
trying to shift.

Regards,
Talwinder Singh

On Sep 28, 4:13 pm, Krishnan Mahadevan
<krishnan.mahadevan1...@gmail.com> wrote:
> You could perhaps think of saving the current frame prior to navigating to
> its child frame.
> Would that help ?
>
> Thanks & Regards
> Krishnan Mahadevan
>
> "All the desirable things in life are either illegal, expensive, fattening
> or in love with someone else!"
>
> On Wed, Sep 28, 2011 at 2:06 PM, Talwinder singh
> <talwindersi...@gmail.com>wrote:

Talwinder singh

unread,
Sep 30, 2011, 12:12:56 AM9/30/11
to webdriver
Hi Daniel Wagner,

I tried this also, it works fine if i have only one level of frames in
a tree, but it doesn't work if i have multilevel frames and iframes,
everytime i do switchTo().defaultcontent() , it takes driver to the
root of the tree which is not what i want, i want it to just shift to
the parent frame node so that i can traverse other branch nodes of
that tree node.

Regards,
Talwinder Singh

On Sep 28, 5:09 pm, Daniel Wagner-Hall <dawag...@gmail.com> wrote:
> driver.switchTo().defaultContent() will take you back to the top level
> - you can traverse back down from there if you have many nested
> frames.
>

Simonz

unread,
Sep 30, 2011, 4:57:06 AM9/30/11
to webdriver

On Sep 30, 2:12 pm, Talwinder singh <talwindersi...@gmail.com> wrote:
> Hi Daniel Wagner,
>
> I tried this also, it works fine if i have only one level of frames in
> a tree, but it doesn't work if i have multilevel frames and iframes,
> everytime i do switchTo().defaultcontent() , it takes driver to the
> root of the tree which is not what i want, i want it to just shift to
> the parent frame node so that i can traverse other branch nodes of
> that tree node.
>
I have the same problem. It is exacerbated by the problem that
WebDriver seems to forget its cache of elements when switching frames
so any WebElements you might have kept around are suddenly invalid
after switching frames (eg: if you try to save the WebElement of the
parent iframe and then switch back to it using
driver.switchTo().frame(parentFrame) => StaleElementException).

In the end I have solved this in the ugliest manner; I store the path
through the tree of frames to the parent frame in terms of a list of
iframe indices. Then I can get back to the parent with
defaultContent() and a series of switchTo().frame(index) calls to
traverse the path.

I would love to know if there is a better way!

Cheers,

Simon

Talwinder singh

unread,
Sep 30, 2011, 7:30:59 AM9/30/11
to webdriver
HI Simon,

you are right, i even tried to save the driver in a tempDriver when
it is at the parent frame, before switching and then tried to assign
the old driver value back to the same instance hoping that it will be
at the parent frame still, it didnt work for me.

Still looking for a better solution.

Regards,
Talwinder Singh

Daniel Wagner-Hall

unread,
Oct 1, 2011, 7:35:17 PM10/1/11
to webd...@googlegroups.com
You had to have a way of getting to the frame originally using frame
identifiers (ids, names, indices) - surely you can just store the
chain of identifiers you used, pop the last one, and replay the last
sequence you executed?
Reply all
Reply to author
Forward
0 new messages