Commit 84a837c4 authored by jkereliuk's avatar jkereliuk Committed by Commit Bot

[ChromeDriver] Implementation of GetElementRect

Spec is here:
https://w3c.github.io/webdriver/webdriver-spec.html#get-element-rect


Bug: chromedriver:1937
Change-Id: I6b035a9f9526fdb5b3ba29c7c0a7269086216d50
Reviewed-on: https://chromium-review.googlesource.com/963044
Commit-Queue: Jonathon Kereliuk <kereliuk@chromium.org>
Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543429}
parent e8d15ffe
......@@ -62,6 +62,8 @@ class Command(object):
HOVER_OVER_ELEMENT = (_Method.POST, '/session/:sessionId/element/:id/hover')
GET_ELEMENT_LOCATION = (
_Method.GET, '/session/:sessionId/element/:id/location')
GET_ELEMENT_RECT = (
_Method.GET, '/session/:sessionId/element/:id/rect')
GET_ELEMENT_LOCATION_ONCE_SCROLLED_INTO_VIEW = (
_Method.GET, '/session/:sessionId/element/:id/location_in_view')
GET_ELEMENT_SIZE = (_Method.GET, '/session/:sessionId/element/:id/size')
......
......@@ -61,5 +61,8 @@ class WebElement(object):
def GetLocation(self):
return self._Execute(Command.GET_ELEMENT_LOCATION)
def GetRect(self):
return self._Execute(Command.GET_ELEMENT_RECT)
def IsDisplayed(self):
return self._Execute(Command.IS_ELEMENT_DISPLAYED)
......@@ -469,6 +469,58 @@ Status ExecuteGetElementLocation(Session* session,
value);
}
Status ExecuteGetElementRect(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::unique_ptr<base::Value> location;
Status status = web_view->CallFunction(
session->GetCurrentFrameId(),
webdriver::atoms::asString(webdriver::atoms::GET_LOCATION), args,
&location);
if (status.IsError())
return status;
std::unique_ptr<base::Value> size;
web_view->CallFunction(session->GetCurrentFrameId(),
webdriver::atoms::asString(webdriver::atoms::GET_SIZE),
args, &size);
// do type conversions
base::DictionaryValue* size_dict;
if (!size->GetAsDictionary(&size_dict))
return Status(kUnknownError, "could not convert to DictionaryValue");
base::DictionaryValue* location_dict;
if (!location->GetAsDictionary(&location_dict))
return Status(kUnknownError, "could not convert to DictionaryValue");
// grab values
int x, y, width, height;
if (!location_dict->GetInteger("x", &x))
return Status(kUnknownError, "getting size failed to return x");
if (!location_dict->GetInteger("y", &y))
return Status(kUnknownError, "getting size failed to return y");
if (!size_dict->GetInteger("height", &height))
return Status(kUnknownError, "getting location failed to return height");
if (!size_dict->GetInteger("width", &width))
return Status(kUnknownError, "getting location failed to return width");
base::DictionaryValue ret;
ret.SetInteger("x", x);
ret.SetInteger("y", y);
ret.SetInteger("width", width);
ret.SetInteger("height", height);
value->reset(ret.DeepCopy());
return Status(kOk);
}
Status ExecuteGetElementLocationOnceScrolledIntoView(
Session* session,
WebView* web_view,
......
......@@ -161,6 +161,12 @@ Status ExecuteGetElementLocation(Session* session,
const base::DictionaryValue& params,
std::unique_ptr<base::Value>* value);
Status ExecuteGetElementRect(Session* session,
WebView* web_view,
const std::string& element_id,
const base::DictionaryValue& params,
std::unique_ptr<base::Value>* value);
// Returns the location of a given element in client coordinates, after
// scrolling it into view.
Status ExecuteGetElementLocationOnceScrolledIntoView(
......
......@@ -317,6 +317,9 @@ HttpHandler::HttpHandler(
CommandMapping(kGet, "session/:sessionId/element/:id/location",
WrapToCommand("GetElementLocation",
base::Bind(&ExecuteGetElementLocation))),
CommandMapping(
kGet, "session/:sessionId/element/:id/rect",
WrapToCommand("GetElementRect", base::Bind(&ExecuteGetElementRect))),
CommandMapping(
kGet, "session/:sessionId/element/:id/location_in_view",
WrapToCommand(
......
......@@ -1362,6 +1362,16 @@ class ChromeDriverTest(ChromeDriverBaseTestWithWebServer):
self._driver.TouchUp(location['x'] + 1, location['y'] + 1)
self.assertEquals('events: touchstart touchmove touchend', events.GetText())
def testGetElementRect(self):
self._driver.Load(self.GetHttpUrlForFile(
'/chromedriver/absolute_position_element.html'))
target = self._driver.FindElement('id', 'target')
rect = target.GetRect()
self.assertEquals(18, rect['x'])
self.assertEquals(10, rect['y'])
self.assertEquals(200, rect['height'])
self.assertEquals(210, rect['width'])
def testTouchScrollElement(self):
self._driver.Load(self.GetHttpUrlForFile(
'/chromedriver/touch_action_tests.html'))
......
<!DOCTYPE html>
<html>
<body>
<div x="80px" y="10px" style="position: absolute; left: 18px; top: 10px; width: 210px; height: 200px;" type="text" id="target">
</body>
</html>
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