Two questions from a beginner.
Q1- Is it possible to assert the existence of an HTML node by ID and class? For example, to see if the following element exists:
<div class="drawer" id="first"....>
I've seen you can use something like:
page.should have_css('div.drawer')
page.should have_css('div#first')
but can we somehow query for the existence of both parameters, I've tried the following and didn't work:
page.should have_selector("div", :class => "drawer", :id => "first")
Q2- Is it possible to add 2 selectors to the 'within' capybara method, ie, I've seen you can limit the scope by doing:
within("//div[@id='first']") do
but can we filter that DIV by adding id='first' and class='drawer' somehow?
Many thanks!
You can combine the selectors.
For your first question, the following checks for a div with id "first" and class "drawer":
page.should have_css('div#first.drawer')
For your second question, the within
block can use the same css-selector as above:
within('div#first.drawer') do
Or if you really prefer xpath, you can do:
within("//div[@id='first' and @class='drawer']") do
A good reference for css-selectors: http://www.w3.org/TR/CSS2/selector.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With