Module: Watir::XpathSupport
Class Method Summary collapse
Instance Method Summary collapse
-
#element_by_xpath(xpath) ⇒ Object
Find the first element matching the given XPath.
-
#elements_by_xpath(xpath) ⇒ Object
Find all elements matching the given XPath.
Class Method Details
.escape(value) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/watir-webdriver/xpath_support.rb', line 27 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 |
# File 'lib/watir-webdriver/xpath_support.rb', line 10 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 |
#elements_by_xpath(xpath) ⇒ Object
Find all elements matching the given XPath
21 22 23 24 25 |
# File 'lib/watir-webdriver/xpath_support.rb', line 21 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 |