Skip to content

Commit b6270ca

Browse files
committed
[rb] add #rect method to Element
1 parent f72fc73 commit b6270ca

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

rb/lib/selenium/webdriver.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module Selenium
3030
module WebDriver
3131
Point = Struct.new(:x, :y)
3232
Dimension = Struct.new(:width, :height)
33+
Rectangle = Struct.new(:x, :y, :width, :height)
3334
Location = Struct.new(:latitude, :longitude, :altitude)
3435

3536
autoload :Chrome, 'selenium/webdriver/chrome'

rb/lib/selenium/webdriver/common/element.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,16 @@ def location
235235
bridge.element_location @id
236236
end
237237

238+
#
239+
# Get the dimensions and coordinates of this element.
240+
#
241+
# @return [WebDriver::Rectangle]
242+
#
243+
244+
def rect
245+
bridge.element_rect @id
246+
end
247+
238248
#
239249
# Determine an element's location on the screen once it has been scrolled into view.
240250
#

rb/lib/selenium/webdriver/remote/bridge.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,13 @@ def element_location(element)
571571
Point.new data['x'], data['y']
572572
end
573573

574+
def element_rect(element)
575+
loc = execute :get_element_location, id: element
576+
size = execute :get_element_size, id: element
577+
578+
Rectangle.new loc['x'], loc['y'], size['width'], size['height']
579+
end
580+
574581
def element_location_once_scrolled_into_view(element)
575582
data = execute :get_element_location_once_scrolled_into_view, id: element
576583

rb/lib/selenium/webdriver/remote/w3c_bridge.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,12 @@ def element_location(element)
516516
Point.new data['x'], data['y']
517517
end
518518

519+
def element_rect(element)
520+
data = execute :get_element_rect, id: element
521+
522+
Rectangle.new data['x'], data['y'], data['width'], data['height']
523+
end
524+
519525
def element_location_once_scrolled_into_view(element)
520526
send_keys_to_element(element, [''])
521527
element_location(element)

rb/spec/integration/selenium/webdriver/element_spec.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,19 @@ module WebDriver
166166
expect(size.width).to be > 0
167167
expect(size.height).to be > 0
168168
end
169+
170+
it 'should get rect' do
171+
driver.navigate.to url_for('xhtmlTest.html')
172+
rect = driver.find_element(class: 'header').rect
173+
174+
expect(rect.x).to be > 0
175+
expect(rect.y).to be > 0
176+
expect(rect.width).to be > 0
177+
expect(rect.height).to be > 0
178+
end
169179
end
170180

171-
# Firefox - "Actions Endpoint Not Yet Implemented"
181+
# Firefox - Pointer actions not in firefox stable yet
172182
not_compliant_on browser: [:safari, :firefox, :ff_nightly] do
173183
it 'should drag and drop' do
174184
driver.navigate.to url_for('dragAndDropTest.html')

0 commit comments

Comments
 (0)