<iframe id="foo"></iframe>
<iframe name="foo">
<iframe>
<iframe name="baz"></iframe>
</iframe>
<iframe name="0" id="bar">
<iframe name="baz"></iframe>
</iframe>
</iframe>
<iframe name="foo.bar">
<iframe name="baz"></iframe>
</iframe>
<iframe name="foo.0.baz"></iframe>
<iframe name="foo.bar.baz"></iframe>
driver.switchTo().frame("foo");
driver.switchTo().frame("foo.bar");
driver.switchTo().frame("baz");
driver.switchTo().frame("foo.0.baz");
driver.switchTo().frame("foo.bar.baz");
WebElement frameContainer = driver.findElement(By.id("my-frame-container"));WebElement frame = frameContainer.findElement(By.xpath(".//iframe[1]"));driver.switchTo().frame(frame);
Simon
> --
> You received this message because you are subscribed to the Google Groups
> "Selenium Developers" group.
> To post to this group, send email to selenium-...@googlegroups.com.
> To unsubscribe from this group, send email to
> selenium-develo...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/selenium-developers?hl=en.
>
- When switching frames, the driver always searches in the currently selected frame and it only accepts exact matches. Switching to a nested frame would require multiple switchTo().frame() commands.
+1
Also, can we clear up the confusion of IDs, names and indices? If
we're getting rid of .s, an int argument can be an index and string
arguments can *never* be treated as indices, but switching by string
accepting either name or ID is another area of ambiguity...
Could you give an example of this? I'm working with one client right now that has lots of frames and the ability to specify a deeply nested frame using driver.switchTo().frame("foo.bar.baz"); is nice.
- When switching frames, the driver always searches in the currently selected frame and it only accepts exact matches. Switching to a nested frame would require multiple switchTo().frame() commands.
<html> // DefaultContent<iframe id="foo"> // A<iframe id="bar"/> // B</iframe><iframe id="bar"/> // C<iframe id="baz"/> // D
// Starting at DefaultContentdriver.switchTo().frame("foo") // At A.switchTo().frame("bar") // At B.switchTo().frame("baz"); // NoSuchFrameExceptiondriver.switchTo().defaultContent() // At DefaultContent.switchTo().frame("bar"); // At C
driver.switchTo().defaultContent() // At DefaultContent.switchTo().frame("baz"); // At D
Would it be
driver.switchTo().frame("foo").frame("bar").frame("baz");
or
driver.switchTo().switchTo().frame("foo").switchTo().frame("bar").switchTo().frame("baz");
Or something else. Neither is all that elegant I think.
driver.switchTo().frame("foo").switchTo().frame("bar").switchTo().frame("baz");
-adam
Michael Tamm has been working on making frame-switching chainable [1]
which was originally going to be
driver.switchTo().frame("foo").frame("bar") and I presume hasn't been
made so yet because it hasn't been implemented across all drivers, and
it's an API change. It certainly looks a lot nicer, and I imagine in
5 years it will be an annoying part of the API not to have changed...