module AutomationObject::Driver::CommonSelenium::Element
Helper module for Selenium based elements
Public Instance Methods
@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 the element field @return [void]
# File lib/automation_object/driver/common_selenium/element.rb, line 64 def clear @subject.clear end
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
@return [String, nil] content of element
# File lib/automation_object/driver/common_selenium/element.rb, line 40 def content @subject.attribute('content') end
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
@return [String, nil] href of element
# File lib/automation_object/driver/common_selenium/element.rb, line 29 def href @subject.attribute('href') end
@return [String, nil] id of element
# File lib/automation_object/driver/common_selenium/element.rb, line 24 def id @subject.attribute('id') end
@return [Boolean] element invisible
# File lib/automation_object/driver/common_selenium/element.rb, line 19 def invisible? @subject.displayed? ? false : true end
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
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
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 of element @return [String, nil]
# File lib/automation_object/driver/common_selenium/element.rb, line 35 def text @subject.text end
@return [Boolean] element visible
# File lib/automation_object/driver/common_selenium/element.rb, line 14 def visible? @subject.displayed? end
Protected Instance Methods
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