1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Move button and link xpaths into XPath class

This commit is contained in:
Jonas Nicklas 2009-12-09 19:17:01 +01:00
parent 39081f3c7d
commit 75730ef137
2 changed files with 12 additions and 4 deletions

View file

@ -138,12 +138,11 @@ module Capybara
alias_method :field_labeled, :find_field
def find_link(locator)
find("//a[@id='#{locator}' or contains(.,'#{locator}') or @title='#{locator}']")
find(XPath.link(locator).to_s)
end
def find_button(locator)
button = find("//input[@type='submit' or @type='image'][@id='#{locator}' or @value='#{locator}']")
button || find("//button[@id='#{locator}' or @value='#{locator}' or contains(.,'#{locator}')]")
find(XPath.button(locator).to_s)
end
private

View file

@ -38,6 +38,15 @@ module Capybara
def fieldset(locator)
append("//fieldset[@id=#{s(locator)} or contains(legend,#{s(locator)})]")
end
def link(locator)
append("//a[@id=#{s(locator)} or contains(.,#{s(locator)}) or @title=#{s(locator)}]")
end
def button(locator)
xpath = append("//input[@type='submit' or @type='image'][@id=#{s(locator)} or @value=#{s(locator)}]")
xpath.append("//button[@id=#{s(locator)} or @value=#{s(locator)} or contains(.,#{s(locator)})]")
end
def text_field(locator)
append("//input[@type='text'][@id=#{s(locator)} or @id=//label[contains(.,#{s(locator)})]/@for]")
@ -71,7 +80,7 @@ module Capybara
@paths.join(' | ')
end
private
protected
# Sanitize a String for putting it into an xpath query
def s(string)