Index: chrome/test/webdriver/session.cc |
=================================================================== |
--- chrome/test/webdriver/session.cc (revision 79141) |
+++ chrome/test/webdriver/session.cc (working copy) |
@@ -2,7 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "chrome/test/webdriver/session_manager.h" |
+#include "chrome/test/webdriver/session.h" |
#include <sstream> |
#include <vector> |
@@ -468,6 +468,29 @@ |
return SwitchToFrameWithJavaScriptLocatedFrame(script, &args); |
} |
+ErrorCode Session::SwitchToFrameWithElement(const WebElementId& element) { |
+ // TODO(jleyba): Extract this, and the other frame switch methods to an atom. |
+ std::string script = |
+ "var element = arguments[0];" |
+ "console.info('Attempting to switch to ' + element);" |
+ "if (element.nodeType != 1 || !/^i?frame$/i.test(element.tagName)) {" |
+ " console.info('Element is not a frame: ' + element + " |
+ "' {nodeType:' + element.nodeType + ',tagName:' + element.tagName + '}');" |
+ " return null;" |
+ "}" |
+ "for (var i = 0; i < window.frames.length; i++) {" |
+ " if (element.contentWindow == window.frames[i]) {" |
+ " return '(//iframe|//frame)[' + (i + 1) + ']';" |
+ " }" |
+ "}" |
+ "console.info('Frame is not connected to this DOM tree');" |
+ "return null;"; |
+ |
+ ListValue args; |
+ args.Append(element.ToValue()); |
+ return SwitchToFrameWithJavaScriptLocatedFrame(script, &args); |
+} |
+ |
void Session::SwitchToTopFrame() { |
current_target_.frame_path = FramePath(); |
} |