Module: Watir::Adjacent

Included in:
Element
Defined in:
lib/watir/adjacent.rb

Instance Method Summary collapse

Instance Method Details

#child(opt = {}) ⇒ Object

Returns element of direct child of current element.

Examples:

browser.form(id: "new_user").child == browser.fieldset
#=> true


94
95
96
# File 'lib/watir/adjacent.rb', line 94

def child(opt = {})
  xpath_adjacent(opt.merge(adjacent: :child, plural: false))
end

#children(opt = {}) ⇒ Object

Returns collection of elements of direct children of current element.

Examples:

children = browser.select_list(id: "new_user_languages").children
children == browser.select_list(id: "new_user_languages").options.to_a
#=> true

Raises:

  • (ArgumentError)


107
108
109
110
111
# File 'lib/watir/adjacent.rb', line 107

def children(opt = {})
  raise ArgumentError, '#children can not take an index value' if opt[:index]

  xpath_adjacent(opt.merge(adjacent: :child, plural: true))
end

#following_sibling(opt = {}) ⇒ Object Also known as: next_sibling

Returns following sibling element of current element.

Examples:

following_sibling = browser.text_field(name: "new_user_first_name").following_sibling(index: 2)
following_sibling == browser.text_field(id: "new_user_last_name")
#=> true


54
55
56
# File 'lib/watir/adjacent.rb', line 54

def following_sibling(opt = {})
  xpath_adjacent(opt.merge(adjacent: :following, plural: false))
end

#following_siblings(opt = {}) ⇒ Object Also known as: next_siblings

Returns collection of following sibling elements of current element.

Examples:

browser.text_field(name: "new_user_first_name").following_siblings.size
#=> 55

Raises:

  • (ArgumentError)


67
68
69
70
71
# File 'lib/watir/adjacent.rb', line 67

def following_siblings(opt = {})
  raise ArgumentError, '#next_siblings can not take an index value' if opt[:index]

  xpath_adjacent(opt.merge(adjacent: :following, plural: true))
end

#parent(opt = {}) ⇒ Object

Returns parent element of current element.

Examples:

browser.text_field(name: "new_user_first_name").parent == browser.fieldset
#=> true


13
14
15
# File 'lib/watir/adjacent.rb', line 13

def parent(opt = {})
  xpath_adjacent(opt.merge(adjacent: :ancestor, plural: false))
end

#preceding_sibling(opt = {}) ⇒ Object Also known as: previous_sibling

Returns preceding sibling element of current element.

Examples:

browser.text_field(name: "new_user_first_name").preceding_sibling(index: 1) == browser.legend
#=> true


25
26
27
# File 'lib/watir/adjacent.rb', line 25

def preceding_sibling(opt = {})
  xpath_adjacent(opt.merge(adjacent: :preceding, plural: false))
end

#preceding_siblings(opt = {}) ⇒ Object Also known as: previous_siblings

Returns collection of preceding sibling elements of current element.

Examples:

browser.text_field(name: "new_user_first_name").preceding_siblings.size
#=> 3

Raises:

  • (ArgumentError)


38
39
40
41
42
# File 'lib/watir/adjacent.rb', line 38

def preceding_siblings(opt = {})
  raise ArgumentError, '#previous_siblings can not take an index value' if opt[:index]

  xpath_adjacent(opt.merge(adjacent: :preceding, plural: true))
end

#siblings(opt = {}) ⇒ Object

Returns collection of siblings of current element, including current element.

Examples:

browser.text_field(name: "new_user_first_name").siblings.size
#=> 59


82
83
84
# File 'lib/watir/adjacent.rb', line 82

def siblings(opt = {})
  parent.children(opt)
end