Module: Watir::XpathSupport

Includes:
Selenium
Included in:
Container
Defined in:
lib/watir-webdriver/xpath_support.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.escape(value) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/watir-webdriver/xpath_support.rb', line 31

def self.escape(value)
  if value.include? "'"
    parts = value.split("'", -1).map { |part| "'#{part}'" }
    string = parts.join(%{,"'",})

    "concat(#{string})"
  else
    "'#{value}'"
  end
end

Instance Method Details

#element_by_xpath(xpath) ⇒ Object

Find the first element matching the given XPath



10
11
12
13
14
15
16
17
# File 'lib/watir-webdriver/xpath_support.rb', line 10

def element_by_xpath(xpath)
  warn 'element_by_xpath is deprecated and replaced by .element(:xpath, ...)'

  e = wd.find_element(:xpath, xpath)
  Watir.element_class_for(e.tag_name.downcase).new(self, :element => e)
rescue WebDriver::Error::NoSuchElementError
  Element.new(self, :xpath => xpath)
end

#elements_by_xpath(xpath) ⇒ Object

Find all elements matching the given XPath



23
24
25
26
27
28
29
# File 'lib/watir-webdriver/xpath_support.rb', line 23

def elements_by_xpath(xpath)
  warn 'elements_by_xpath is deprecated and replaced by .elements(:xpath, ...)'

  wd.find_elements(:xpath, xpath).map do |e|
    Watir.element_class_for(e.tag_name.downcase).new(self, :element => e)
  end
end