Commit 373c511f authored by craigdh@chromium.org's avatar craigdh@chromium.org

[ChromeDriver] Implement SwitchToFrame by element command.

BUG=166797
TEST=run_py_tests.py testSwitchToFrame


Review URL: https://chromiumcodereview.appspot.com/12217149

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182169 0039d316-1c4b-4281-b951-d872f2087c98
parent 90870aa3
...@@ -122,6 +122,10 @@ class ChromeDriverTest(unittest.TestCase): ...@@ -122,6 +122,10 @@ class ChromeDriverTest(unittest.TestCase):
self.assertTrue(self._driver.ExecuteScript('return window.top == window')) self.assertTrue(self._driver.ExecuteScript('return window.top == window'))
self._driver.SwitchToFrameByIndex(0) self._driver.SwitchToFrameByIndex(0)
self.assertTrue(self._driver.ExecuteScript('return window.top != window')) self.assertTrue(self._driver.ExecuteScript('return window.top != window'))
self._driver.SwitchToMainFrame()
self.assertTrue(self._driver.ExecuteScript('return window.top == window'))
self._driver.SwitchToFrame(self._driver.FindElement('tag name', 'iframe'))
self.assertTrue(self._driver.ExecuteScript('return window.top != window'))
def testExecuteInRemovedFrame(self): def testExecuteInRemovedFrame(self):
self._driver.ExecuteScript( self._driver.ExecuteScript(
......
...@@ -122,30 +122,34 @@ Status ExecuteSwitchToFrame( ...@@ -122,30 +122,34 @@ Status ExecuteSwitchToFrame(
return Status(kOk); return Status(kOk);
} }
std::string evaluate_xpath_script = std::string script;
"function(xpath) {" base::ListValue args;
" return document.evaluate(xpath, document, null, " const base::DictionaryValue* id_dict;
" XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;" if (id->GetAsDictionary(&id_dict)) {
"}"; script = "function(elem) { return elem; }";
std::string xpath = "(/html/body//iframe|/html/frameset/frame)"; args.Append(id_dict->DeepCopy());
std::string id_string;
int id_int;
if (id->GetAsString(&id_string)) {
xpath += base::StringPrintf(
"[@name=\"%s\" or @id=\"%s\"]", id_string.c_str(), id_string.c_str());
} else if (id->GetAsInteger(&id_int)) {
xpath += base::StringPrintf("[%d]", id_int + 1);
} else if (id->IsType(base::Value::TYPE_DICTIONARY)) {
// TODO(kkania): Implement.
return Status(kUnknownError, "frame switching by element not implemented");
} else { } else {
return Status(kUnknownError, "invalid 'id'"); script =
"function(xpath) {"
" return document.evaluate(xpath, document, null, "
" XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;"
"}";
std::string xpath = "(/html/body//iframe|/html/frameset/frame)";
std::string id_string;
int id_int;
if (id->GetAsString(&id_string)) {
xpath += base::StringPrintf(
"[@name=\"%s\" or @id=\"%s\"]", id_string.c_str(), id_string.c_str());
} else if (id->GetAsInteger(&id_int)) {
xpath += base::StringPrintf("[%d]", id_int + 1);
} else {
return Status(kUnknownError, "invalid 'id'");
}
args.Append(new base::StringValue(xpath));
} }
base::ListValue args;
args.Append(new base::StringValue(xpath));
std::string frame; std::string frame;
Status status = web_view->GetFrameByFunction( Status status = web_view->GetFrameByFunction(
session->frame, evaluate_xpath_script, args, &frame); session->frame, script, args, &frame);
if (status.IsError()) if (status.IsError())
return status; return status;
session->frame = frame; session->frame = frame;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment