Class: PageObject::Elements::Element

Inherits:
Object
  • Object
show all
Includes:
NestedElements
Defined in:
lib/page-object/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 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, platform) ⇒ Element

Returns a new instance of Element.



16
17
18
19
# File 'lib/page-object/elements/element.rb', line 16

def initialize(element, platform)
  @element = element
  include_platform_for platform
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object

delegate calls to driver element



90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/page-object/elements/element.rb', line 90

def method_missing(*args, &block)
  m = args.shift
  $stderr.puts "*** DEPRECATION WARNING"
  $stderr.puts "*** You are calling a method named #{m} at #{caller[0]}."
  $stderr.puts "*** This method does not exist in page-object 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 page-object method."
  $stderr.puts "*** If you are using functionality that does not exist in page-object please request it be added."
  begin
    element.send m, *args, &block
  rescue Exception => e
    raise
  end
end

Instance Attribute Details

#elementObject (readonly)

Returns the value of attribute element.



14
15
16
# File 'lib/page-object/elements/element.rb', line 14

def element
  @element
end

Class Method Details

.selenium_identifier_for(identifier) ⇒ Object



77
78
79
80
81
82
83
84
85
86
# File 'lib/page-object/elements/element.rb', line 77

def self.selenium_identifier_for identifier
  if identifier.length == 1
    identifier = identifier_for identifier, selenium_finders, selenium_mapping
    return identifier.keys.first, identifier.values.first
  elsif identifier.length > 1
    how = :xpath
    what = build_xpath_for identifier
    return how, what
  end
end

.watir_identifier_for(identifier) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/page-object/elements/element.rb', line 61

def self.watir_identifier_for identifier
  if should_build_watir_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 each, watir_finders, watir_mapping
    all_identities[ident.keys.first] = ident.values.first
  end
  all_identities
end

Instance Method Details

#clickObject

click the element



24
25
26
# File 'lib/page-object/elements/element.rb', line 24

def click
  element.click
end

#disabled?Boolean

return true if the element is not enabled

Returns:

  • (Boolean)


45
46
47
# File 'lib/page-object/elements/element.rb', line 45

def disabled?
  not enabled?
end

#double_clickObject

double click the element



31
32
33
# File 'lib/page-object/elements/element.rb', line 31

def double_click
  element.double_click
end

#enabled?Boolean

return true if the element is enabled

Returns:

  • (Boolean)


38
39
40
# File 'lib/page-object/elements/element.rb', line 38

def enabled?
  element.enabled?
end

#inspectObject



56
57
58
# File 'lib/page-object/elements/element.rb', line 56

def inspect
  element.inspect
end

#style(property) ⇒ Object

get the value of the given CSS property



52
53
54
# File 'lib/page-object/elements/element.rb', line 52

def style(property)
  element.style property
end