Cucumbers and Capybara, button click without link or button

I am trying to test the inplace editor using the Cucumber / Capybara / Selenium stack, but my problem is that the editor is activated by clicking on a div, not a link or button. I can't seem to figure out how to get Capybara to do this. Is there any way to do this?

+44
selenium integration-testing webdriver cucumber capybara
Aug 27 '10 at 15:08
source share
2 answers

You can click an element through Capybara::Element.click . I add the following for this in my web_steps.rb to click the div.

 When /^(?:|I )click within "([^"]*)"$/ do |selector| find(selector).click end 

There is also Element.trigger('mouseover') , which allows you to enable freezing, although it does not work with Selenium.

It is also very likely that you will need to decorate your feature / script with Capybara with the @javascript tag.

+62
Oct 08 '10 at 10:30
source share

Besides the ability to click on button elements, for example @Jim Mitchener, you can also click on a part of the text as follows:

 # WhenI click on the text "Sign in" When(/^I click on text "(.*?)"$/) do |text| click_text(text) end def click_text(text) elem = find(:xpath, "//*[contains(translate(text(), '#{text.upcase}', '#{text.downcase}'), '#{text.downcase}')]", match: :first, wait: false) scroll_to(elem, -200) elem.click end 

This helper function performs the same function as find(selector).click , it finds a text element.

I found this article very well, it explains the various types of steps that you can write in cucumbers.

0
Mar 16 '18 at 15:36
source share



All Articles