Cucumber and Capybara, clicking a non-link or button element

前端 未结 2 1472
没有蜡笔的小新
没有蜡笔的小新 2020-12-13 06:16

I am trying to test an inplace editor using Cucumber/Capybara/Selenium stack, but my problem is that the editor is activated by clicking a div and not a link or button. I ca

2条回答
  •  情话喂你
    2020-12-13 06:34

    Besides being able to click on button elements like @Jim Mitchener explained, you can also click on a part of a text in the following way:

    # 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 does the same thing as find(selector).click, it finds the text element.

    I found this article very good, it explains different types of steps you can write in cucumber.

提交回复
热议问题