Class: Watir::ElementLocator
- Inherits:
-
Object
- Object
- Watir::ElementLocator
- Includes:
- Exception
- Defined in:
- lib/watir-webdriver/locators/element_locator.rb
Direct Known Subclasses
ButtonLocator, ChildCellLocator, ChildRowLocator, TextFieldLocator
Constant Summary
- WD_FINDERS =
[ :class, :class_name, :css, :id, :link, :link_text, # :name, # deliberately excluded to be watirspec compliant :partial_link_text, :tag_name, :xpath ]
Instance Method Summary (collapse)
-
- (ElementLocator) initialize(wd, selector, valid_attributes)
constructor
A new instance of ElementLocator.
- - (Object) locate
- - (Object) locate_all
Constructor Details
- (ElementLocator) initialize(wd, selector, valid_attributes)
A new instance of ElementLocator
19 20 21 22 23 |
# File 'lib/watir-webdriver/locators/element_locator.rb', line 19 def initialize(wd, selector, valid_attributes) @wd = wd @selector = selector.dup @valid_attributes = valid_attributes end |
Instance Method Details
- (Object) locate
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/watir-webdriver/locators/element_locator.rb', line 25 def locate e = by_id and return e # short-circuit if :id is given if @selector.size == 1 element = find_first_by_one else element = find_first_by_multiple end # this actually only applies when finding by xpath - browser.text_field(:xpath, "//input[@type='radio']") # we don't need to validate the element if we built the xpath ourselves. validate_element(element) if element rescue Selenium::WebDriver::Error::NoSuchElementError nil end |
- (Object) locate_all
42 43 44 45 46 47 48 |
# File 'lib/watir-webdriver/locators/element_locator.rb', line 42 def locate_all if @selector.size == 1 find_all_by_one else find_all_by_multiple end end |