Class: CapybaraPageObject::Element
- Inherits:
-
Object
- Object
- CapybaraPageObject::Element
show all
- Defined in:
- lib/capybara_page_object/elements/element.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(element, page) ⇒ Element
Returns a new instance of Element.
6
7
8
9
|
# File 'lib/capybara_page_object/elements/element.rb', line 6
def initialize(element, page)
@element = element
@page = page
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
55
56
57
58
59
60
61
62
63
|
# File 'lib/capybara_page_object/elements/element.rb', line 55
def method_missing(method_name, *arguments, &block)
if element.respond_to?(method_name, true)
element.send(method_name, *arguments, &block)
elsif value = element[method_name.to_s]
value
else
super
end
end
|
Instance Attribute Details
#element ⇒ Object
Returns the value of attribute element.
3
4
5
|
# File 'lib/capybara_page_object/elements/element.rb', line 3
def element
@element
end
|
#page ⇒ Object
Returns the value of attribute page.
3
4
5
|
# File 'lib/capybara_page_object/elements/element.rb', line 3
def page
@page
end
|
Instance Method Details
#attribute(name) ⇒ Object
11
12
13
|
# File 'lib/capybara_page_object/elements/element.rb', line 11
def attribute(name)
element[name.to_s]
end
|
#class ⇒ Object
Also known as:
class_name
19
20
21
|
# File 'lib/capybara_page_object/elements/element.rb', line 19
def class
attribute('class')
end
|
#enabled? ⇒ Boolean
15
16
17
|
# File 'lib/capybara_page_object/elements/element.rb', line 15
def enabled?
!element.disabled?
end
|
#focus ⇒ Object
24
25
26
|
# File 'lib/capybara_page_object/elements/element.rb', line 24
def focus
bridge.executeScript("return arguments[0].focus()", native)
end
|
#html ⇒ Object
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/capybara_page_object/elements/element.rb', line 33
def html
case native.class.to_s
when /Nokogiri/
native.to_html
when /Selenium/
native['outerHTML']
else
raise "This driver is not supported for retrieving the html of an element"
end
end
|
#native ⇒ Object
44
45
46
|
# File 'lib/capybara_page_object/elements/element.rb', line 44
def native
element.native
end
|
#parent ⇒ Object
28
29
30
31
|
# File 'lib/capybara_page_object/elements/element.rb', line 28
def parent
raise Capybara::NotSupportedByDriverError unless javascript_enabled?
element.parent
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
65
66
67
68
69
|
# File 'lib/capybara_page_object/elements/element.rb', line 65
def respond_to_missing?(method_name, include_private = false)
element.respond_to?(method_name, include_private) ||
element[method_name.to_s] != nil ||
super
end
|
48
49
50
51
52
53
|
# File 'lib/capybara_page_object/elements/element.rb', line 48
def scroll_into_view
unless element.native.respond_to?(:location_once_scrolled_into_view)
raise "Selenium javascript driver required to use 'scroll_into_view'"
end
element.native.location_once_scrolled_into_view
end
|
#within(&block) ⇒ Object
71
72
73
|
# File 'lib/capybara_page_object/elements/element.rb', line 71
def within(&block)
page.within(element, &block)
end
|