Sha256: 1833e82f6d6db6768bf48138c19be9b16c221084ab1cc2023ffc9363c2d533b1

Contents?: true

Size: 903 Bytes

Versions: 16

Compression:

Stored size: 903 Bytes

Contents

# encoding: utf-8
module Watir
  module XpathSupport
    include Selenium

    #
    # Find the first element matching the given XPath
    #

    def element_by_xpath(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

    #
    # Find all elements matching the given XPath
    #

    def elements_by_xpath(xpath)
      wd.find_elements(:xpath, xpath).map do |e|
        Watir.element_class_for(e.tag_name.downcase).new(self, :element => e)
      end
    end
    
    def self.escape(value)
      if value.include? "'"
        parts = value.split("'", -1).map { |part| "'#{part}'" }
        string = parts.join(%{,"'",})

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

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
watir-webdriver-0.3.9 lib/watir-webdriver/xpath_support.rb
watir-webdriver-0.3.8 lib/watir-webdriver/xpath_support.rb
watir-webdriver-0.3.7 lib/watir-webdriver/xpath_support.rb
watir-webdriver-0.3.6 lib/watir-webdriver/xpath_support.rb
watir-webdriver-0.3.5 lib/watir-webdriver/xpath_support.rb
watir-webdriver-0.3.4 lib/watir-webdriver/xpath_support.rb
watir-webdriver-0.3.3 lib/watir-webdriver/xpath_support.rb
watir-webdriver-0.3.2 lib/watir-webdriver/xpath_support.rb
watir-webdriver-0.3.1 lib/watir-webdriver/xpath_support.rb
watir-webdriver-0.3.0 lib/watir-webdriver/xpath_support.rb
watir-webdriver-0.2.9 lib/watir-webdriver/xpath_support.rb
watir-webdriver-0.2.8 lib/watir-webdriver/xpath_support.rb
watir-webdriver-0.2.7 lib/watir-webdriver/xpath_support.rb
watir-webdriver-0.2.6 lib/watir-webdriver/xpath_support.rb
watir-webdriver-0.2.5 lib/watir-webdriver/xpath_support.rb
watir-webdriver-0.2.4 lib/watir-webdriver/xpath_support.rb