Created
May 17, 2011 16:51
-
-
Save velenux/976835 to your computer and use it in GitHub Desktop.
Select a link via XPath by it's content and container class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
# using XPath 1.0, ref: http://www.exampledepot.com/egs/org.w3c.dom/xpath_GetElemByText.html | |
class XPathFactory | |
# build a XPath to find any link with content "content" inside a | |
# container with class "class_name" | |
def by_container_class_and_link_content(class_name, content) | |
"//*[@class and contains(concat(' ',normalize-space(@class),' ')," + | |
"' #{class_name} ')]//a[contains(translate(.,'abcdefghijklmnopqrstuvwxyz'," + | |
"'ABCDEFGHIJKLMNOPQRSTUVWXYZ'),'#{content.upcase}')]" | |
end | |
end | |
xpath_build = XPathFactory.new | |
element_xpath = xpath_build.by_container_class_and_link_content('find-me-class', 'Click me link') | |
puts element_xpath | |
# use in watir, etc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment