I searched and I can’t find a way to do this.
We run Capybara tests with the Poltergeist driver in cucumbers in the EmberJS / Rails application. I cannot use page.driver.debug because I am running inside a headless stray instance, so troubleshooting is not available to me, but the screenshots work, and the Chrome dev tools for checking on the page in question show the correct elements.
I have a cucumber script that does not work, and because the find does not work. My test is as follows:
When(/^I delete description "(.*?)"$/) do |description| within :css, '#myform' do first('label', :text => /#{description}/).find(:xpath, '..').find(:css, 'button.delete') end end
He cannot find this element. Here is the corresponding DOM section:
<form id="myform"> <div class="row-fluid question"> <div class="span12"> <div class="padding"> <div id="ember576" class="ember-view is-viewing-edit-controls"> <button class="delete" data-ember-action="31"></button> <button class="edit" data-ember-action="32"></button> <button class="insert_above" data-ember-action="33"></button> <button class="insert_below" data-ember-action="34"></button> <button class="move_up" data-ember-action="35"></button> <button class="move_down" data-ember-action="36"></button> <label class="question" data-ember-action="37">Enter your first name</label> <input id="ember577" class="ember-view ember-text-field"> <span class="error"></span> </div> </div> </div> </div> </form>
If I add to binding.pry, this is:
first('label', :text => /#{description}/).find(:xpath, '..') │
gives me this answer:
=> #<Capybara::Element tag="div">
And this:
first('label', :text => /#{description}/).find(:xpath, '..') │
gives me this answer:
=> "Enter your first name"
but a complete find:
first('label', :text => /#{description}/).find(:xpath, '..').find(:css, 'button.delete')
gives me this answer:
Capybara::ElementNotFound: Unable to find css "button.delete"
I have a feeling that this is a parent / sister problem, but I cannot fix it. So I think I have a few questions:
- For debugging, is there anyway with a poltergeist driver a list of all the children?
- Is there something wrong with my xpath selector? The fact that
.. returns Capybara::Element tag="div" makes me think that I have the correct parent element (and, as I said, it works on other pages in other similar tests), but I have there is no way to check which element it is. I can not find how to get xpath or anything else that helps me identify the element.