This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 24635 - switchToFrame should only accept a WebElement or number argument.
Summary: switchToFrame should only accept a WebElement or number argument.
Status: RESOLVED FIXED
Alias: None
Product: Browser Test/Tools WG
Classification: Unclassified
Component: WebDriver (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Browser Testing and Tools WG
QA Contact: Browser Testing and Tools WG
URL:
Whiteboard:
Keywords:
: 24837 24989 (view as bug list)
Depends on:
Blocks: 20860
  Show dependency treegraph
 
Reported: 2014-02-12 21:45 UTC by jleyba
Modified: 2014-03-10 21:45 UTC (History)
5 users (show)

See Also:


Attachments
frame_switching_patch.txt (8.77 KB, text/plain)
2014-02-27 23:46 UTC, Luke Inman-Semerau
Details

Description jleyba 2014-02-12 21:45:46 UTC
https://dvcs.w3.org/hg/webdriver/raw-file/default/webdriver-spec.html#switching-frames

switchToFrame currently accepts a WebElement (as a reference to an iframe/frame element), DOMString (as the frame name or id), or number (the frame index) as an argument.

The spec should be updated to drop support for DOMString, as these selection methods are redundant with WebElement. Furthermore, even though the spec outlines how DOMString should be handled, it is ambiguous from an API perspective.  Given a DOMString argument, should WebDriver select the frame with that name, or the frame with that ID?

By supporting only an index number or WebElement reference, switchToFrame would present an unambiguous API with clearly defined behavior.  To select a frame by name:

webElement = findElement(Locator("name", "X"))
switchToFrame(webElement)

Likewise, to switch to a frame by ID:

webElement = findElement(Locator("id", "X"))
switchToFrame(webElement)
Comment 1 Alexei Barantsev 2014-02-13 21:25:14 UTC
I suggest to deprecate swithing by index too. Yes, it is unambiguous, but the order of frames can vary among browsers.

According to the specification switching by number is equivalent of the JS expression "window.frames[n]".

Let's consider a sample: http://jsfiddle.net/barancev/e6ahn/2/show/light/

This page has a static iframe (let's call it "8uua7") and a dynamic iframe (let's call it "2P8u6") created by JS and inserted before the static one. So the tree (DOM) order of frames is 1) "2P8u6", 2) "8uua7".

What browsers think about the order of the frames in the array window.frames on this page?

IE: 1) "2P8u6", 2) "8uua7", all right.
Firefox: 1) "8uua7", 2) "2P8u6", the order is opposite to the tree order.
Chrome: 1) "8uua7", 2) "2P8u6", the same as Firefox.

And as soon as the browser behaviour is incosistent here we'd better not propagate this incosistency to the WebDriver API.
Comment 2 David Burns :automatedtester 2014-02-14 16:46:29 UTC
reading http://www.whatwg.org/specs/web-apps/current-work/multipage/browsers.html#accessing-other-browsing-contexts it would appear that Chrome and Firefox do not conform to this which means using it by index 

Raised https://bugzilla.mozilla.org/show_bug.cgi?id=972902 related to this
Comment 3 David Burns :automatedtester 2014-02-25 21:50:10 UTC
we are going to remove the locators by name and ID.

We will keep window.frames[n] and WebElement with WebElement being the favoured way.
Comment 4 Luke Inman-Semerau 2014-02-27 23:45:03 UTC
*** Bug 24837 has been marked as a duplicate of this bug. ***
Comment 5 Luke Inman-Semerau 2014-02-27 23:46:05 UTC
Created attachment 1441 [details]
frame_switching_patch.txt
Comment 6 Luke Inman-Semerau 2014-03-10 18:05:13 UTC
*** Bug 24989 has been marked as a duplicate of this bug. ***
Comment 7 David Burns :automatedtester 2014-03-10 21:45:57 UTC
landed in https://dvcs.w3.org/hg/webdriver/rev/561e13778acb