Class: Applitools::Selenium::Element

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/applitools/selenium/element.rb

Constant Summary collapse

TRACE_PREFIX =
'EyesWebElement'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(driver, element) ⇒ Element

Returns a new instance of Element.



5
6
7
8
9
# File 'lib/applitools/selenium/element.rb', line 5

def initialize(driver, element)
  super(element)

  @driver = driver
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



27
28
29
# File 'lib/applitools/selenium/element.rb', line 27

def ==(other)
  other.is_a?(web_element.class) && web_element == other
end

#clickObject



15
16
17
18
19
20
21
# File 'lib/applitools/selenium/element.rb', line 15

def click
  current_control = region
  offset = current_control.middle_offset
  @driver.user_inputs << Applitools::Base::MouseTrigger.new(:click, current_control, offset)

  web_element.click
end

#inspectObject



23
24
25
# File 'lib/applitools/selenium/element.rb', line 23

def inspect
  TRACE_PREFIX + web_element.inspect
end

#regionObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/applitools/selenium/element.rb', line 42

def region
  point = location
  left = point.x
  top = point.y
  width = 0
  height = 0

  begin
    dimension = size
    width = dimension.width
    height = dimension.height
  rescue => e
    # Not supported on all platforms.
    Applitools::EyesLogger.error("Failed extracting size using JavaScript: (#{e.message})")
  end

  if left < 0
    width = [0, width + left].max
    left = 0
  end

  if top < 0
    height = [0, height + top].max
    top = 0
  end

  Applitools::Base::Region.new(left, top, width, height)
end

#send_keys(*args) ⇒ Object Also known as: send_key



32
33
34
35
36
37
38
39
# File 'lib/applitools/selenium/element.rb', line 32

def send_keys(*args)
  current_control = region
  Selenium::WebDriver::Keys.encode(args).each do |key|
    @driver.user_inputs << Applitools::Base::TextTrigger.new(key.to_s, current_control)
  end

  web_element.send_keys(*args)
end

#web_elementObject



11
12
13
# File 'lib/applitools/selenium/element.rb', line 11

def web_element
  @web_element ||= __getobj__
end