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; |