Class: SK::Element
- Inherits:
-
Object
show all
- Defined in:
- lib/element.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(arg, src = "xxx") ⇒ Element
Returns a new instance of Element.
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/element.rb', line 3
def initialize(arg,src="xxx")
if !arg
@locator = { src: src }
@el = false
elsif arg.instance_of?(Selenium::WebDriver::Element)
@locator = { src: src }
@el = arg
else @locator = arg @el = SK::Browser.find(arg)
SK::Trace.debug "element locator=#{arg} el=#{@el}"
SK::Trace.warn "element failed to initialize with locator = #{arg}" unless @el
end
end
|
Instance Attribute Details
#el ⇒ Object
Returns the value of attribute el.
21
22
23
|
# File 'lib/element.rb', line 21
def el
@el
end
|
#locator ⇒ Object
Returns the value of attribute locator.
22
23
24
|
# File 'lib/element.rb', line 22
def locator
@locator
end
|
Instance Method Details
#children(locator, klass = SK::Element) ⇒ Object
81
82
83
84
85
86
|
# File 'lib/element.rb', line 81
def children(locator,klass=SK::Element)
els = SK::Browser.rescue_exceptions { self.el.find_elements(locator) }
els.map { |el| klass.new(el) }
end
|
#displayed? ⇒ Boolean
33
34
35
36
|
# File 'lib/element.rb', line 33
def displayed?
puts "+++ element displayed?"
SK::Browser.rescue_exceptions { self.el.displayed? }
end
|
#enabled? ⇒ Boolean
43
44
45
46
47
48
|
# File 'lib/element.rb', line 43
def enabled?
puts "enabled? 1:#{exists?}"
false unless exists?
puts "enabled? 2:#{el.enabled?}"
el.enabled?
end
|
#exists? ⇒ Boolean
Also known as:
exist?
28
29
30
|
# File 'lib/element.rb', line 28
def exists?
!!el
end
|
#find(locator, klass = SK::Element) ⇒ Object
Also known as:
child
57
58
59
60
61
62
|
# File 'lib/element.rb', line 57
def find(locator,klass=SK::Element)
child_el = find_child_el(locator)
klass.new(child_el,"#{locator}")
end
|
#find_child_el(locator) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/element.rb', line 65
def find_child_el(locator)
case
when locator.has_key?(:value)
search(:value,locator[:value])
when locator.has_key?(:type)
search(:type,locator[:type])
else
SK::Browser.rescue_exceptions { self.el.find_element(locator) }
end
end
|
#html ⇒ Object
38
39
40
41
|
# File 'lib/element.rb', line 38
def html
self.el.attribute('innerHTML')
end
|
#parent_el ⇒ Object
100
101
102
|
# File 'lib/element.rb', line 100
def parent_el
self.el.find_element({xpath: ".."})
end
|
#search(key, val) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/element.rb', line 88
def search(key,val)
trace "element#search key=#{key} val=#{val}"
elements = self.el.find_elements({})
elements.find do |e|
e.attribute(key) == val
end
end
|
#text ⇒ Object
50
51
52
53
54
55
|
# File 'lib/element.rb', line 50
def text
str1 = self.el ? self.el.text : ''
str1.gsub(/\n+/, " ").strip end
|
#to_s ⇒ Object
24
25
26
|
# File 'lib/element.rb', line 24
def to_s
"<SK::Element #{locator}>"
end
|