module AutomationObject::Driver::CommonSelenium::Element

Helper module for Selenium based elements

Public Instance Methods

attribute(key, value = false) click to toggle source

@param key [String] attribute key to get or set @param value [Object] optional value to set the key as @return [Object] value of attribute

# 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
clear() click to toggle source

Clear the element field @return [void]

# File lib/automation_object/driver/common_selenium/element.rb, line 64
def clear
  @subject.clear
end
click() click to toggle source

Perform a click action on the element @return [void]

# File lib/automation_object/driver/common_selenium/element.rb, line 76
def click
  scroll_into_view if @driver.browser?
  @subject.click
end
content() click to toggle source

@return [String, nil] content of element

# File lib/automation_object/driver/common_selenium/element.rb, line 40
def content
  @subject.attribute('content')
end
hover() click to toggle source

Hover over element

# File lib/automation_object/driver/common_selenium/element.rb, line 82
def hover
  scroll_into_view
  @driver.action.move_to(@subject).perform
end
href() click to toggle source

@return [String, nil] href of element

# File lib/automation_object/driver/common_selenium/element.rb, line 29
def href
  @subject.attribute('href')
end
id() click to toggle source

@return [String, nil] id of element

# File lib/automation_object/driver/common_selenium/element.rb, line 24
def id
  @subject.attribute('id')
end
invisible?() click to toggle source

@return [Boolean] element invisible

# File lib/automation_object/driver/common_selenium/element.rb, line 19
def invisible?
  @subject.displayed? ? false : true
end
send_keys(string) click to toggle source

Type into an element @return [void]

# File lib/automation_object/driver/common_selenium/element.rb, line 58
def send_keys(string)
  @subject.send_keys(string)
end
submit() click to toggle source

Perform a submit action on an element @return [void]

# File lib/automation_object/driver/common_selenium/element.rb, line 70
def submit
  @subject.submit
end
switch_to_iframe() click to toggle source

Helper method to switch to this element's iframe

# File lib/automation_object/driver/common_selenium/element.rb, line 88
def switch_to_iframe
  @driver.switch_to.frame(iframe_switch_value)
end
text() click to toggle source

Text of element @return [String, nil]

# File lib/automation_object/driver/common_selenium/element.rb, line 35
def text
  @subject.text
end
visible?() click to toggle source

@return [Boolean] element visible

# File lib/automation_object/driver/common_selenium/element.rb, line 14
def visible?
  @subject.displayed?
end

Protected Instance Methods

iframe_switch_value() click to toggle source

Helper method for getting the value to switch to If value doesn't exist then create one @return [String] iframe value to switch to

# File lib/automation_object/driver/common_selenium/element.rb, line 97
def iframe_switch_value
  iframe_switch_value = attribute('id')
  iframe_switch_value = attribute('name') if iframe_switch_value.length.zero?

  iframe_switch_value = attribute('name', SecureRandom.hex(16)) unless iframe_switch_value

  iframe_switch_value
end