Commit 23ce277b authored by John Chen's avatar John Chen Committed by Commit Bot

[ChromeDriver] Fix W3C Element Send Keys

In W3C mode, Element Send Keys command should get keys from string
property "text", instead of list property "value".

Bug: chromedriver:2649
Change-Id: I68b915ad572c289364d797aa34496b2278cb3997
Reviewed-on: https://chromium-review.googlesource.com/c/1320208Reviewed-by: default avatarCaleb Rouleau <crouleau@chromium.org>
Commit-Queue: John Chen <johnchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605848}
parent d31efeca
......@@ -312,7 +312,8 @@ class ChromeDriver(object):
if (not self.w3c_compliant and 'status' in response
and response['status'] != 0):
raise _ExceptionForLegacyResponse(response)
elif self.w3c_compliant and 'error' in response['value']:
elif (self.w3c_compliant and response['value'] is not None
and 'error' in response['value']):
raise _ExceptionForStandardResponse(response)
return response
......
......@@ -61,6 +61,9 @@ class WebElement(object):
typing.append(value[i])
self._Execute(Command.SEND_KEYS_TO_ELEMENT, {'value': typing})
def SendKeysW3c(self, text):
self._Execute(Command.SEND_KEYS_TO_ELEMENT, {'text': text})
def GetLocation(self):
return self._Execute(Command.GET_ELEMENT_LOCATION)
......
......@@ -319,8 +319,17 @@ Status ExecuteSendKeysToElement(Session* session,
const base::DictionaryValue& params,
std::unique_ptr<base::Value>* value) {
const base::ListValue* key_list;
if (!params.GetList("value", &key_list))
return Status(kUnknownError, "'value' must be a list");
base::ListValue key_list_local;
if (session->w3c_compliant) {
const base::Value* text;
if (!params.Get("text", &text) || !text->is_string())
return Status(kInvalidArgument, "'text' must be a string");
key_list_local.Set(0, std::make_unique<base::Value>(text->Clone()));
key_list = &key_list_local;
} else {
if (!params.GetList("value", &key_list))
return Status(kUnknownError, "'value' must be a list");
}
bool is_input = false;
Status status = IsElementAttributeEqualToIgnoreCase(
......
......@@ -1757,6 +1757,29 @@ class ChromeDriverTest(ChromeDriverBaseTestWithWebServer):
self.assertEquals('test', report['type']);
self.assertEquals('test report message', report['body']['message']);
# Tests in the following class are expected to be moved to ChromeDriverTest
# class when we no longer support the legacy mode.
class ChromeDriverW3cTest(ChromeDriverBaseTestWithWebServer):
"""W3C mode specific tests."""
def setUp(self):
self._driver = self.CreateDriver(
send_w3c_capability=True, send_w3c_request=True)
def testSendKeysToElement(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
text = self._driver.ExecuteScript(
'document.body.innerHTML = \'<input type="text">\';'
'var input = document.getElementsByTagName("input")[0];'
'input.addEventListener("change", function() {'
' document.body.appendChild(document.createElement("br"));'
'});'
'return input;')
text.SendKeysW3c('0123456789+-*/ Hi')
text.SendKeysW3c(', there!')
value = self._driver.ExecuteScript('return arguments[0].value;', text)
self.assertEquals('0123456789+-*/ Hi, there!', value)
class ChromeDriverSiteIsolation(ChromeDriverBaseTestWithWebServer):
"""Tests for ChromeDriver with the new Site Isolation Chrome feature.
......
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