module AutomationObject::Driver::CommonSelenium::ElementGeometry

Helper module for Selenium based elements

Public Instance Methods

box_coordinates() click to toggle source

@return [BoxCoordinates] :x1, :x2, :y1, :y2 coordinates of a box

# File lib/automation_object/driver/common_selenium/element_geometry.rb, line 55
def box_coordinates
  element_location = @subject.location
  element_size = @subject.size

  box_coordinates = BoxCoordinates.new
  box_coordinates.x1 = element_location.x.to_f
  box_coordinates.y1 = element_location.y.to_f
  box_coordinates.x2 = element_location.x.to_f + element_size.width.to_f
  box_coordinates.y2 = element_location.y.to_f + element_size.height.to_f

  box_coordinates
end
collides_with_element?(second_element_object, collision_tolerance = 0) click to toggle source

@param second_element_object [Object] element to compare to @param collision_tolerance [Numeric] pixel tolerance of collisions @return [Boolean] element collides with other

# File lib/automation_object/driver/common_selenium/element_geometry.rb, line 71
def collides_with_element?(second_element_object, collision_tolerance = 0)
  box_one = box_coordinates
  box_two = second_element_object.box_coordinates

  if box_one.x2 > box_two.x1 && box_one.x1 < box_two.x2 && box_one.y2 > box_two.y1 && box_one.y1 < box_two.y2
    if box_one.x2 > (box_two.x1 + collision_tolerance) && (box_one.x1 + collision_tolerance) < box_two.x2 &&
       box_one.y2 > (box_two.y1 + collision_tolerance) && (box_one.y1 + collision_tolerance) < box_two.y2
      return true
    end
  end

  false
end
element_center() click to toggle source

@return [Hash] :x, :y coordinates

# File lib/automation_object/driver/common_selenium/element_geometry.rb, line 43
def element_center
  element_location = @subject.location
  element_size = @subject.size

  center = Point.new
  center.x = (element_location.x.to_f + element_size.width.to_f / 2).to_f
  center.y = (element_location.y.to_f + element_size.height.to_f / 2).to_f

  center
end
height() click to toggle source

@return [Numeric] height of element

# File lib/automation_object/driver/common_selenium/element_geometry.rb, line 26
def height
  @subject.size.height
end
location() click to toggle source

Get the location @return [Point]

# File lib/automation_object/driver/common_selenium/element_geometry.rb, line 32
def location
  @subject.location
end
size() click to toggle source

Get the size of an element @return [Dimension]

# File lib/automation_object/driver/common_selenium/element_geometry.rb, line 38
def size
  @subject.size
end
width() click to toggle source

@return [Numeric] width of element

# File lib/automation_object/driver/common_selenium/element_geometry.rb, line 21
def width
  @subject.size.width
end
x() click to toggle source

@return [Numeric] x position of element

# File lib/automation_object/driver/common_selenium/element_geometry.rb, line 11
def x
  @subject.location.x
end
y() click to toggle source

@return [Numeric] y position of element

# File lib/automation_object/driver/common_selenium/element_geometry.rb, line 16
def y
  @subject.location.y
end