Module: XPath::HTML
- Extended by:
- HTML
- Includes:
- XPath
- Included in:
- HTML
- Defined in:
- lib/xpath/html.rb
Constant Summary
Constants included
from XPath
VERSION
Instance Method Summary
collapse
Methods included from XPath
#anywhere, #attr, #child, #contains, #css, #current, #descendant, generate, #name, #string, #tag, #text, #var, #varstring
Instance Method Details
16
17
18
19
20
|
# File 'lib/xpath/html.rb', line 16
def button(locator)
button = descendant(:input)[attr(:type).one_of('submit', 'image', 'button')][attr(:id).equals(locator) | attr(:value).is(locator)]
button += descendant(:button)[attr(:id).equals(locator) | attr(:value).is(locator) | string.n.is(locator)]
button += descendant(:input)[attr(:type).equals('image')][attr(:alt).is(locator)]
end
|
#checkbox(locator, options = {}) ⇒ Object
60
61
62
|
# File 'lib/xpath/html.rb', line 60
def checkbox(locator, options={})
xpath = locate_field(descendant(:input)[attr(:type).equals('checkbox')], locator)
end
|
#content(locator) ⇒ Object
12
13
14
|
# File 'lib/xpath/html.rb', line 12
def content(locator)
child(:"descendant-or-self::*")[current.n.contains(locator)]
end
|
#field(locator, options = {}) ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/xpath/html.rb', line 30
def field(locator, options={})
xpath = descendant(:input, :textarea, :select)[~attr(:type).one_of('submit', 'image', 'hidden')]
xpath = locate_field(xpath, locator)
xpath = xpath[attr(:checked)] if options[:checked]
xpath = xpath[~attr(:checked)] if options[:unchecked]
xpath = xpath[field_value(options[:with])] if options.has_key?(:with)
xpath
end
|
#fieldset(locator) ⇒ Object
26
27
28
|
# File 'lib/xpath/html.rb', line 26
def fieldset(locator)
descendant(:fieldset)[attr(:id).equals(locator) | descendant(:legend)[string.n.is(locator)]]
end
|
#file_field(locator, options = {}) ⇒ Object
68
69
70
|
# File 'lib/xpath/html.rb', line 68
def file_field(locator, options={})
locate_field(descendant(:input)[attr(:type).equals('file')], locator)
end
|
#fillable_field(locator, options = {}) ⇒ Object
39
40
41
42
43
44
|
# File 'lib/xpath/html.rb', line 39
def fillable_field(locator, options={})
xpath = descendant(:input, :textarea)[~attr(:type).one_of('submit', 'image', 'radio', 'checkbox', 'hidden', 'file')]
xpath = locate_field(xpath, locator)
xpath = xpath[field_value(options[:with])] if options.has_key?(:with)
xpath
end
|
#link(locator, options = {}) ⇒ Object
6
7
8
9
10
|
# File 'lib/xpath/html.rb', line 6
def link(locator, options={})
href = options[:href]
link = descendant(:a)[href ? attr(:href).equals(href) : attr(:href)]
link[attr(:id).equals(locator) | string.n.is(locator) | attr(:title).is(locator) | descendant(:img)[attr(:alt).is(locator)]]
end
|
22
23
24
|
# File 'lib/xpath/html.rb', line 22
def link_or_button(locator)
link(locator) + button(locator)
end
|
#optgroup(name) ⇒ Object
72
73
74
|
# File 'lib/xpath/html.rb', line 72
def optgroup(name)
descendant(:optgroup)[attr(:label).is(name)]
end
|
#option(name) ⇒ Object
76
77
78
|
# File 'lib/xpath/html.rb', line 76
def option(name)
descendant(:option)[string.n.is(name)]
end
|
64
65
66
|
# File 'lib/xpath/html.rb', line 64
def radio_button(locator, options={})
locate_field(descendant(:input)[attr(:type).equals('radio')], locator)
end
|
#select(locator, options = {}) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/xpath/html.rb', line 46
def select(locator, options={})
xpath = locate_field(descendant(:select), locator)
options[:options].each do |option|
xpath = xpath[descendant(:option).equals(option)]
end if options[:options]
[options[:selected]].flatten.each do |option|
xpath = xpath[descendant(:option)[attr(:selected)].equals(option)]
end if options[:selected]
xpath
end
|
#table(locator, options = {}) ⇒ Object
80
81
82
83
84
|
# File 'lib/xpath/html.rb', line 80
def table(locator, options={})
xpath = descendant(:table)[attr(:id).equals(locator) | descendant(:caption).contains(locator)]
xpath = xpath[table_rows(options[:rows])] if options[:rows]
xpath
end
|
#table_row(cells) ⇒ Object
94
95
96
97
98
99
100
|
# File 'lib/xpath/html.rb', line 94
def table_row(cells)
cell_conditions = child(:td, :th)[string.n.equals(cells.first)]
cells.drop(1).each do |cell|
cell_conditions = cell_conditions.next_sibling(:td, :th)[string.n.equals(cell)]
end
cell_conditions
end
|
#table_rows(rows) ⇒ Object
86
87
88
89
90
91
92
|
# File 'lib/xpath/html.rb', line 86
def table_rows(rows)
row_conditions = descendant(:tr)[table_row(rows.first)]
rows.drop(1).each do |row|
row_conditions = row_conditions.next_sibling(:tr)[table_row(row)]
end
row_conditions
end
|