Skip to content

Instantly share code, notes, and snippets.

@ajvargo
Created December 16, 2009 01:43
Show Gist options
  • Save ajvargo/257503 to your computer and use it in GitHub Desktop.
Save ajvargo/257503 to your computer and use it in GitHub Desktop.
# uses xpath to check for a form element based on the label,
# instead of using a css selector w/ label_for
# name should be the complete name in the html page.
# meaning Title: and not Title
# find the label that is name. Get the "for" of the label
# uses the for to check for the input with that as an id
Then /^I should see a "([^\"]*)" for "([^\"]*)"$/ do |type, name|
case type
when 'Button'
response.should have_xpath("//input[@type='submit' and @value='#{name}']")
when 'Text Field'
response.should have_xpath("//input[@type='text' and @id=..//label[normalize-space(text())=\"#{name}\"]//@for]")
when 'Text Area'
response.should have_xpath("//textarea[@id=..//label[normalize-space(text())=\"#{name}\"]//@for]")
when 'Radio Button'
pending
when 'Select Field'
response.should have_xpath("//select[@id=..//label[normalize-space(text())=\"#{name}\"]//@for]")
else pending
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment