Class: Locator::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/locator/element.rb,
lib/locator/element/area.rb,
lib/locator/element/file.rb,
lib/locator/element/form.rb,
lib/locator/element/link.rb,
lib/locator/element/field.rb,
lib/locator/element/input.rb,
lib/locator/element/label.rb,
lib/locator/element/button.rb,
lib/locator/element/select.rb,
lib/locator/element/check_box.rb,
lib/locator/element/text_area.rb,
lib/locator/element/form_element.rb,
lib/locator/element/hidden_field.rb,
lib/locator/element/radio_button.rb,
lib/locator/element/elements_list.rb,
lib/locator/element/select_option.rb,
lib/locator/element/labeled_element.rb

Defined Under Namespace

Classes: Area, Button, CheckBox, ElementsList, Field, File, Form, FormElement, HiddenField, Input, Label, LabeledElement, Link, RadioButton, Select, SelectOption, TextArea

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Element

Returns a new instance of Element.



26
27
28
29
30
31
# File 'lib/locator/element.rb', line 26

def initialize(*args)
  attributes, name = args.last.is_a?(Hash) ? args.pop : {}, args.pop
  @name = name
  @attributes = attributes
  @locatables = ((attributes.delete(:matches) || [:content]) + [:id]).uniq
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



24
25
26
# File 'lib/locator/element.rb', line 24

def attributes
  @attributes
end

#cssObject (readonly)

Returns the value of attribute css.



24
25
26
# File 'lib/locator/element.rb', line 24

def css
  @css
end

#locatablesObject (readonly)

Returns the value of attribute locatables.



24
25
26
# File 'lib/locator/element.rb', line 24

def locatables
  @locatables
end

#nameObject (readonly)

Returns the value of attribute name.



24
25
26
# File 'lib/locator/element.rb', line 24

def name
  @name
end

Instance Method Details

#all(scope, *args) ⇒ Object



37
38
39
40
41
42
# File 'lib/locator/element.rb', line 37

def all(scope, *args)
  attributes, selector = args.last.is_a?(Hash) ? args.pop : {}, args.pop
  result = lookup(scope, selector, attributes)
  result.sort! if selector
  result
end

#locate(*args) ⇒ Object



33
34
35
# File 'lib/locator/element.rb', line 33

def locate(*args)
  all(*args).first
end

#xpath(attributes = {}) ⇒ Object



44
45
46
# File 'lib/locator/element.rb', line 44

def xpath(attributes = {})
  @xpath ||= Xpath.new(name || '*', self.attributes.merge(attributes)).to_s
end