Class: Druid::Elements::Element

Inherits:
Object
  • Object
show all
Includes:
Assist, NestedElements
Defined in:
lib/druid/elements/element.rb

Overview

Contains functionality that is common across all elements

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Assist

#button_for, #buttons_for, #cell_for, #cell_text_for, #cells_for, #check_checkbox, #checkbox_checked?, #checkbox_for, #checkboxes_for, #clear_radio, #click_button_for, #click_link_for, #div_for, #div_text_for, #divs_for, #element_for, #file_field_for, #file_field_value_set, #file_fields_for, #form_for, #forms_for, #h1_for, #h1_text_for, #h1s_for, #h2_for, #h2_text_for, #h2s_for, #h3_for, #h3_text_for, #h3s_for, #h4_for, #h4_text_for, #h4s_for, #h5_for, #h5_text_for, #h5s_for, #h6_for, #h6_text_for, #h6s_for, #hidden_field_for, #hidden_field_value_for, #hidden_fields_for, #image_for, #images_for, #label_for, #label_text_for, #labels_for, #link_for, #links_for, #list_item_for, #list_item_text_for, #list_items_for, #ordered_list_for, #ordered_lists_for, #paragraph_for, #paragraph_text_for, #paragraphs_for, #radio_button_for, #radio_buttons_for, #radio_selected?, #select_list_for, #select_list_value_for, #select_list_value_set, #select_lists_for, #select_radio, #span_for, #span_text_for, #spans_for, #table_for, #tables_for, #text_area_for, #text_area_value_for, #text_area_value_set, #text_areas_for, #text_field_for, #text_field_value_for, #text_field_value_set, #text_fields_for, #uncheck_checkbox, #unordered_list_for, #unordered_lists_for

Methods included from NestedElements

#button_element, #button_elements, #cell_element, #cell_elements, #checkbox_element, #checkbox_elements, #div_element, #div_elements, #file_field_element, #form_element, #form_elements, #h1_element, #h1_elements, #h2_element, #h2_elements, #h3_element, #h3_elements, #h4_element, #h4_elements, #h5_element, #h5_elements, #h6_element, #h6_elements, #hidden_field_element, #hidden_field_elements, #image_element, #image_elements, #label_element, #label_elements, #link_element, #link_elements, #list_item_element, #list_item_elements, #ordered_list_element, #ordered_list_elements, #paragraph_element, #paragraph_elements, #radio_button_element, #radio_button_elements, #select_list_element, #select_list_elements, #span_element, #span_elements, #table_element, #table_elements, #text_area_element, #text_area_elements, #text_field_element, #text_field_elements, #unordered_list_element, #unordered_list_elements

Constructor Details

#initialize(element) ⇒ Element

Returns a new instance of Element.



15
16
17
18
# File 'lib/druid/elements/element.rb', line 15

def initialize(element)
  @element = element
  @driver = @element
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object

delegate calls to driver element



237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/druid/elements/element.rb', line 237

def method_missing(m, *args, &block)
  $stderr.puts "*** DEPRECATION WARNING"
  $stderr.puts "*** You are calling a method named #{m} at #{caller[0]}."
  $stderr.puts "*** This method does not exist in druid so it is being passed to the driver."
  $stderr.puts "*** This feature will be removed in the near future."
  $stderr.puts "*** Please change your code to call the correct druid method."
  $stderr.puts "*** If you are using functionality that does not exist in druid please request it be added."
  unless element.respond_to?(m)
    raise NoMethodError, "undefined method `#{m}` for #{element.inspect}:#{element.class}"
  end
  element.__send__(m, *args, &block)
end

Instance Attribute Details

#driverObject

Returns the value of attribute driver.



13
14
15
# File 'lib/druid/elements/element.rb', line 13

def driver
  @driver
end

#elementObject

Returns the value of attribute element.



12
13
14
# File 'lib/druid/elements/element.rb', line 12

def element
  @element
end

Class Method Details

.identifier_for(identifier) ⇒ Object



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/druid/elements/element.rb', line 219

def self.identifier_for identifier
  if have_to_build_xpath(identifier)
    how = :xpath
    what = build_xpath_for(identifier)
    return how => what
  end
  all_identities = {}
  identifier.each do |key, value|
    each = {key => value}
    ident = identifier_for_element each, finders, mapping
    all_identities[ident.keys.first] = ident.values.first
  end
  all_identities
  # end
end

Instance Method Details

#==(other) ⇒ Boolean

compare this element to another to determine if they are equal

Returns:

  • (Boolean)


60
61
62
# File 'lib/druid/elements/element.rb', line 60

def ==(other)
  element == other.element
end

#attribute(attribute_name) ⇒ String?

Get the value of the given attribute of the element

Parameters:

Returns:



78
79
80
# File 'lib/druid/elements/element.rb', line 78

def attribute(attribute_name)
  element.attribute_value attribute_name
end

#clearObject

clear the contents of the element



118
119
120
# File 'lib/druid/elements/element.rb', line 118

def clear
  element.clear
end

#clickObject

Click this element



85
86
87
# File 'lib/druid/elements/element.rb', line 85

def click
  element.click
end

#disabled?Boolean

return true if the element is not enabled

Returns:

  • (Boolean)


39
40
41
# File 'lib/druid/elements/element.rb', line 39

def disabled?
  not enabled?
end

#double_clickObject

double click this element



125
126
127
# File 'lib/druid/elements/element.rb', line 125

def double_click
  element.double_click
end

#enabled?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/druid/elements/element.rb', line 33

def enabled?
  element.enabled?
end

#exist?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/druid/elements/element.rb', line 29

def exist?
  element.exist?
end

#fire_event(event_name) ⇒ Object

Fire the provided event on the current element



139
140
141
# File 'lib/druid/elements/element.rb', line 139

def fire_event(event_name)
  element.fire_event(event_name)
end

#flashObject

Flash the element by temporarily changing the background color



150
151
152
# File 'lib/druid/elements/element.rb', line 150

def flash
  element.flash
end

#focusObject



143
144
145
# File 'lib/druid/elements/element.rb', line 143

def focus
  element.focus
end

#inspectObject



96
97
98
# File 'lib/druid/elements/element.rb', line 96

def inspect
  element.inspect
end

#parentObject

Returns parent element of current element.



156
157
158
159
160
161
# File 'lib/druid/elements/element.rb', line 156

def parent
  parent = element.parent
  type = element.type if parent.tag_name.to_sym == :input
  cls = Druid::Elements.element_class_for(parent.tag_name, type)
  cls.new(parent)
end

#right_clickObject

right click this element



132
133
134
# File 'lib/druid/elements/element.rb', line 132

def right_click
  element.right_click
end

#send_keys(*args) ⇒ Object

Send keystrokes to this element

Examples:

element.send_keys "foo"                    #=> value: 'foo'
element.send_keys "tet", :arrow_left, "s"  #=> value: 'test'
element.send_keys [:control, 'a'], :space  #=> value: ' '

Parameters:



111
112
113
# File 'lib/druid/elements/element.rb', line 111

def send_keys(*args)
  element.send_keys(*args)
end

#style(property) ⇒ Object

get the value of the given CSS property



92
93
94
# File 'lib/druid/elements/element.rb', line 92

def style(property)
  element.style property
end

#tag_nameString

Get the tag name of this element

Returns:



69
70
71
# File 'lib/druid/elements/element.rb', line 69

def tag_name
  element.tag_name
end

#textString

Get the text for the element

Returns:



25
26
27
# File 'lib/druid/elements/element.rb', line 25

def text
  element.text
end

#valueString

Get the value of this element

Returns:



52
53
54
# File 'lib/druid/elements/element.rb', line 52

def value
  element.value
end

#visible?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/druid/elements/element.rb', line 43

def visible?
  element.visible?
end

#wait_until(timeout = Druid.default_element_wait, message = nil, &block) ⇒ Object

Waits until the block returns true

Parameters:

  • (default (Integer)

    to:5) seconds to wait before timing out



213
214
215
# File 'lib/druid/elements/element.rb', line 213

def wait_until(timeout=Druid.default_element_wait, message=nil, &block)
  Watir::Wait.until(timeout, message, &block)
end

#when_not_present(timeout = Druid.default_element_wait) ⇒ Object

Waits until the element is not present

timing out

Parameters:

  • (defaults (Integer)

    to: 5) seconds to wait before



180
181
182
# File 'lib/druid/elements/element.rb', line 180

def when_not_present(timeout=Druid.default_element_wait)
  element.wait_while_present(timeout)
end

#when_not_visible(timeout = Druid.default_element_wait) ⇒ Object

Waits until the element is not visible

Parameters:

  • (default (Integer)

    to:5) seconds to wait before timing out



201
202
203
204
205
206
# File 'lib/druid/elements/element.rb', line 201

def when_not_visible(timeout=Druid.default_element_wait)
  Watir::Wait.while(timeout, "Element still visible after #{timeout} seconds") do
    visible?
  end
  self
end

#when_present(timeout = Druid.default_element_wait) ⇒ Object

Waits until the element is present

timing out

Parameters:

  • (defaults (Integer)

    to: 5) seconds to wait before



169
170
171
172
# File 'lib/druid/elements/element.rb', line 169

def when_present(timeout=Druid.default_element_wait)
  element.wait_until_present(timeout)
  self
end

#when_visible(timeout = Druid.default_element_wait) ⇒ Object

Waits until the element is visible

Parameters:

  • (default (Interger)

    to:5) seconds to wait before timing out



189
190
191
192
193
194
# File 'lib/druid/elements/element.rb', line 189

def when_visible(timeout=Druid.default_element_wait)
  Watir::Wait.until(timeout, "Element was not visible in #{timeout} seconds") do
    visible?
  end
  self
end