Module: AutomationObject::Driver::CommonSelenium::Element

Includes:
ElementGeometry
Included in:
AppiumAdapter::Element, SeleniumAdapter::Element
Defined in:
lib/automation_object/driver/common_selenium/element.rb

Overview

Helper module for Selenium based elements

Instance Method Summary collapse

Methods included from ElementGeometry

#box_coordinates, #collides_with_element?, #element_center, #height, #location, #size, #width, #x, #y

Instance Method Details

#attribute(key, value = false) ⇒ Object

Returns value of attribute

Parameters:

  • key (String)

    attribute key to get or set

  • value (Object) (defaults to: false)

    optional value to set the key as

Returns:

  • (Object)

    value of attribute



47
48
49
50
51
52
53
54
# File 'lib/automation_object/driver/common_selenium/element.rb', line 47

def attribute(key, value = false)
  if value
    script = "return arguments[0].#{key} = '#{value}'"
    @driver.execute_script(script, @subject)
  end

  @subject.attribute(key)
end

#clearvoid

This method returns an undefined value.

Clear the element field



64
65
66
# File 'lib/automation_object/driver/common_selenium/element.rb', line 64

def clear
  @subject.clear
end

#clickvoid

This method returns an undefined value.

Perform a click action on the element



76
77
78
79
# File 'lib/automation_object/driver/common_selenium/element.rb', line 76

def click
  scroll_into_view if @driver.browser?
  @subject.click
end

#contentString?

Returns content of element

Returns:

  • (String, nil)

    content of element



40
41
42
# File 'lib/automation_object/driver/common_selenium/element.rb', line 40

def content
  @subject.attribute('content')
end

#hoverObject

Hover over element



82
83
84
85
# File 'lib/automation_object/driver/common_selenium/element.rb', line 82

def hover
  scroll_into_view
  @driver.action.move_to(@subject).perform
end

#hrefString?

Returns href of element

Returns:

  • (String, nil)

    href of element



29
30
31
# File 'lib/automation_object/driver/common_selenium/element.rb', line 29

def href
  @subject.attribute('href')
end

#idString?

Returns id of element

Returns:

  • (String, nil)

    id of element



24
25
26
# File 'lib/automation_object/driver/common_selenium/element.rb', line 24

def id
  @subject.attribute('id')
end

#invisible?Boolean

Returns element invisible

Returns:

  • (Boolean)

    element invisible



19
20
21
# File 'lib/automation_object/driver/common_selenium/element.rb', line 19

def invisible?
  @subject.displayed? ? false : true
end

#send_keys(string) ⇒ void

This method returns an undefined value.

Type into an element



58
59
60
# File 'lib/automation_object/driver/common_selenium/element.rb', line 58

def send_keys(string)
  @subject.send_keys(string)
end

#submitvoid

This method returns an undefined value.

Perform a submit action on an element



70
71
72
# File 'lib/automation_object/driver/common_selenium/element.rb', line 70

def submit
  @subject.submit
end

#switch_to_iframeObject

Helper method to switch to this element's iframe



88
89
90
# File 'lib/automation_object/driver/common_selenium/element.rb', line 88

def switch_to_iframe
  @driver.switch_to.frame(iframe_switch_value)
end

#textString?

Text of element

Returns:



35
36
37
# File 'lib/automation_object/driver/common_selenium/element.rb', line 35

def text
  @subject.text
end

#visible?Boolean

Returns element visible

Returns:

  • (Boolean)

    element visible



14
15
16
# File 'lib/automation_object/driver/common_selenium/element.rb', line 14

def visible?
  @subject.displayed?
end