I’m using Selenium WebDriver (v2.2) to “switch” to the “top” frame like so:
webdriver.SwitchTo().Frame("relative=top");
This generates an error message:
Unable to locate frame: relative=top
Can this be caused because the page I’m using has no frames?
EDIT
Unfortunately, both solutions that involve window switching fail:
webdriver.SwitchTo().Window(winHandle);
webdriver.SwitchTo().DefaultContent();
Strictly speaking, actually, they don’t fail. But, here’s the problem: Let’s say I fetch an IWebElement within a frame. Here’s what the code roughly looks like:
descend-into-the-frame
grab-the-element
ascend-out-of-the-frame-to-the-top
use-the-element
When I use-the-element, I get a “Element does not exist in the cache” exception. This is because the ascend-out-of-the-frame-to-the-top switches the window, which clears the cache. Quite annoying. I have figured out a workaround, though:
ascend-out-of-the-frame-to-the-top
descend-into-the-frame
grab-the-element
use-the-element
This still means I have to watch out for element-not-in-the-cache situations. But at least as long as I use an element immediately after fetching it, I’m ok.
Thanks for the help everyone!
I assume you Selenium IDE gave you that code when you switched from one frame to another. What I did is to store the window handle of the parent window, so that you can switch back to it later.