Skip to content

Commit

Permalink
[ChromeDriver] Implement Get element property
Browse files Browse the repository at this point in the history
Bug: chromedriver:1936
Change-Id: I9e385f3249226d886c49023126582a96e4687d82
Reviewed-on: https://chromium-review.googlesource.com/1231913
Reviewed-by: John Chen <johnchen@chromium.org>
Commit-Queue: Tatiana Buldina <buldina@chromium.org>
Cr-Commit-Position: refs/heads/master@{#592285}
  • Loading branch information
Tatiana Buldina authored and Commit Bot committed Sep 19, 2018
1 parent 02a0bc1 commit 34e575b
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 1 deletion.
2 changes: 2 additions & 0 deletions chrome/test/chromedriver/client/command_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class Command(object):
GET_ELEMENT_SIZE = (_Method.GET, '/session/:sessionId/element/:id/size')
GET_ELEMENT_ATTRIBUTE = (
_Method.GET, '/session/:sessionId/element/:id/attribute/:name')
GET_ELEMENT_PROPERTY = (
_Method.GET, '/session/:sessionId/element/:id/property/:name')
ELEMENT_EQUALS = (
_Method.GET, '/session/:sessionId/element/:id/equals/:other')
GET_COOKIES = (_Method.GET, '/session/:sessionId/cookie')
Expand Down
3 changes: 3 additions & 0 deletions chrome/test/chromedriver/client/webelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def GetText(self):
def GetAttribute(self,name):
return self._Execute(Command.GET_ELEMENT_ATTRIBUTE, {'name': name})

def GetProperty(self,name):
return self._Execute(Command.GET_ELEMENT_PROPERTY, {'name': name})

def HoverOver(self):
self._Execute(Command.HOVER_OVER_ELEMENT)

Expand Down
20 changes: 20 additions & 0 deletions chrome/test/chromedriver/element_commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,26 @@ Status ExecuteGetElementValue(Session* session,
value);
}

Status ExecuteGetElementProperty(Session* session,
WebView* web_view,
const std::string& element_id,
const base::DictionaryValue& params,
std::unique_ptr<base::Value>* value) {
base::ListValue args;
args.Append(CreateElement(element_id));

std::string name;
if (!params.GetString("name", &name))
return Status(kUnknownError, "missing 'name'");
args.AppendString(name);

return web_view->CallFunction(
session->GetCurrentFrameId(),
"function(elem, name) { return elem[name] }",
args,
value);
}

Status ExecuteGetElementTagName(Session* session,
WebView* web_view,
const std::string& element_id,
Expand Down
7 changes: 7 additions & 0 deletions chrome/test/chromedriver/element_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ Status ExecuteGetElementValue(Session* session,
const base::DictionaryValue& params,
std::unique_ptr<base::Value>* value);

// Returns the value of a given element property.
Status ExecuteGetElementProperty(Session* session,
WebView* web_view,
const std::string& element_id,
const base::DictionaryValue& params,
std::unique_ptr<base::Value>* value);

// Returns the lower case tag name of a given element.
Status ExecuteGetElementTagName(Session* session,
WebView* web_view,
Expand Down
2 changes: 2 additions & 0 deletions chrome/test/chromedriver/log_replay/client_replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ class Method(object):
"GetCookies": (Method.GET, "/session/:sessionId/cookie"),
"GetElementAttribute":
(Method.GET, "/session/:sessionId/element/:id/attribute/:name"),
"GetElementProperty":
(Method.GET, "/session/:sessionId/element/:id/property/:name"),
"GetElementCSSProperty":
(Method.GET, "/session/:sessionId/element/:id/css/:propertyName"),
"GetElementLocation":
Expand Down
3 changes: 3 additions & 0 deletions chrome/test/chromedriver/server/http_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ HttpHandler::HttpHandler(
CommandMapping(kGet, "session/:sessionId/element/:id/attribute/:name",
WrapToCommand("GetElementAttribute",
base::Bind(&ExecuteGetElementAttribute))),
CommandMapping(kGet, "session/:sessionId/element/:id/property/:name",
WrapToCommand("GetElementProperty",
base::Bind(&ExecuteGetElementProperty))),
CommandMapping(
kGet, "session/:sessionId/element/:id/css/:propertyName",
WrapToCommand("GetElementCSSProperty",
Expand Down
7 changes: 7 additions & 0 deletions chrome/test/chromedriver/test/run_py_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,13 @@ def testGetElementAttribute(self):
elem = self._driver.FindElement("name", "phones")
self.assertEquals('3', elem.GetAttribute('size'))

def testGetElementProperty(self):
self._driver.Load(self.GetHttpUrlForFile(
'/chromedriver/two_inputs.html'))
elem = self._driver.FindElement("id", "first")
self.assertEquals('text', elem.GetProperty('type'))
self.assertEquals('first', elem.GetProperty('id'))

def testGetElementSpecialCharAttribute(self):
self._driver.Load(self.GetHttpUrlForFile(
'/chromedriver/attribute_colon_test.html'))
Expand Down
2 changes: 1 addition & 1 deletion docs/chromedriver_status.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Below is a list of all WebDriver commands and their current support in ChromeDri
| POST | /session/{session id}/element/{element id}/elements | Find Elements From Element | |
| GET | /session/{session id}/element/{element id}/selected | Is Element Selected | |
| GET | /session/{session id}/element/{element id}/attribute/{name} | Get Element Attribute | |
| GET | /session/{session id}/element/{element id}/property/{name} | Get Element Property | Incomplete | [1936](https://bugs.chromium.org/p/chromedriver/issues/detail?id=1936)
| GET | /session/{session id}/element/{element id}/property/{name} | Get Element Property | Complete |
| GET | /session/{session id}/element/{element id}/css/{property name} | Get Element CSS Value | Partially Complete | [1994](https://bugs.chromium.org/p/chromedriver/issues/detail?id=1994)
| GET | /session/{session id}/element/{element id}/text | Get Element Text | Complete |
| GET | /session/{session id}/element/{element id}/name | Get Element Tag Name | Complete |
Expand Down

0 comments on commit 34e575b

Please sign in to comment.