Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(980)

Unified Diff: chrome/test/chromedriver/window_commands.cc

Issue 12217149: [ChromeDriver] Implement SwitchToFrame by element command. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/chromedriver/run_py_tests.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/chromedriver/window_commands.cc
diff --git a/chrome/test/chromedriver/window_commands.cc b/chrome/test/chromedriver/window_commands.cc
index 50ffad8f75a26f6657cb60c8684b93b20f02e13f..081a16f1a5d6a937bcd9f0d38498578ef0468dca 100644
--- a/chrome/test/chromedriver/window_commands.cc
+++ b/chrome/test/chromedriver/window_commands.cc
@@ -122,30 +122,34 @@ Status ExecuteSwitchToFrame(
return Status(kOk);
}
- std::string evaluate_xpath_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 if (id->IsType(base::Value::TYPE_DICTIONARY)) {
- // TODO(kkania): Implement.
- return Status(kUnknownError, "frame switching by element not implemented");
+ std::string script;
+ base::ListValue args;
+ const base::DictionaryValue* id_dict;
+ if (id->GetAsDictionary(&id_dict)) {
+ script = "function(elem) { return elem; }";
+ args.Append(id_dict->DeepCopy());
} 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;
Status status = web_view->GetFrameByFunction(
- session->frame, evaluate_xpath_script, args, &frame);
+ session->frame, script, args, &frame);
if (status.IsError())
return status;
session->frame = frame;
« no previous file with comments | « chrome/test/chromedriver/run_py_tests.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698