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
15
16
17
18
19
|
# File 'lib/xpath/html.rb', line 15
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
59
60
61
|
# File 'lib/xpath/html.rb', line 59
def checkbox(locator, options={})
xpath = locate_field(descendant(:input)[attr(:type).equals('checkbox')], locator)
end
|
#content(locator) ⇒ Object
11
12
13
|
# File 'lib/xpath/html.rb', line 11
def content(locator)
child(:"descendant-or-self::*")[current.n.contains(locator)]
end
|
#field(locator, options = {}) ⇒ Object
29
30
31
32
33
34
35
36
|
# File 'lib/xpath/html.rb', line 29
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
25
26
27
|
# File 'lib/xpath/html.rb', line 25
def fieldset(locator)
descendant(:fieldset)[attr(:id).equals(locator) | descendant(:legend)[text.is(locator)]]
end
|
#file_field(locator, options = {}) ⇒ Object
67
68
69
|
# File 'lib/xpath/html.rb', line 67
def file_field(locator, options={})
locate_field(descendant(:input)[attr(:type).equals('file')], locator)
end
|
#fillable_field(locator, options = {}) ⇒ Object
38
39
40
41
42
43
|
# File 'lib/xpath/html.rb', line 38
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) ⇒ Object
6
7
8
9
|
# File 'lib/xpath/html.rb', line 6
def link(locator)
link = descendant(:a)[attr(:href)]
link[attr(:id).equals(locator) | string.n.is(locator) | attr(:title).is(locator) | descendant(:img)[attr(:alt).is(locator)]]
end
|
21
22
23
|
# File 'lib/xpath/html.rb', line 21
def link_or_button(locator)
link(locator) + button(locator)
end
|
#option(name) ⇒ Object
71
72
73
|
# File 'lib/xpath/html.rb', line 71
def option(name)
descendant(:option)[text.n.is(name)]
end
|
63
64
65
|
# File 'lib/xpath/html.rb', line 63
def radio_button(locator, options={})
locate_field(descendant(:input)[attr(:type).equals('radio')], locator)
end
|
#select(locator, options = {}) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/xpath/html.rb', line 45
def select(locator, options={})
xpath = locate_field(descendant(:select), locator)
options[:options].each do |option|
xpath = xpath[descendant(:option).text.equals(option)]
end if options[:options]
[options[:selected]].flatten.each do |option|
xpath = xpath[descendant(:option)[attr(:selected)].text.equals(option)]
end if options[:selected]
xpath
end
|
#table(locator, options = {}) ⇒ Object
75
76
77
78
79
|
# File 'lib/xpath/html.rb', line 75
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
89
90
91
92
93
94
95
|
# File 'lib/xpath/html.rb', line 89
def table_row(cells)
cell_conditions = child(:td, :th)[text.equals(cells.first)]
cells.drop(1).each do |cell|
cell_conditions = cell_conditions.next_sibling(:td, :th)[text.equals(cell)]
end
cell_conditions
end
|
#table_rows(rows) ⇒ Object
81
82
83
84
85
86
87
|
# File 'lib/xpath/html.rb', line 81
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
|