这是我观点的一部分......
<input type="image" id="clickAction" src="<%= @bookSurveyImage %>" alt="Take Survey"%>"/>
<% end %>
</body>
</html>
我希望能够定位该输入,重定向到另一个网址。我怎样才能做到这一点 ?请帮忙
以下是我尝试过的一些方法。
describe "landings", :type => :feature do
it "index: get all params" do
visit '/sample_page?'
expect(page).to have_no_content 'Sample text'
expect(page).to have_no_content 'Example'
expect(page).to have_no_content("Some Content")
expect(page).to have_css("img", :maximum => 1)
# expect(page).to have_css("input", :id => "sampleID")
# get :survey_link
# expect(response).to render_template(:survey_link) #
# find("#clickAction").click
# input[@type='image']
# click_input
#
# visit 'https://url........'
结束 结束
您应该可以点击它
click_button("Take Survey")
http://www.rubydoc.info/gems/capybara/Capybara/Node/Actions#click_button-instance_method
你可以使用水豚的find方法。您可以根据元素的 id 属性(在本例中为“clickAction”)来定位该元素。以下是如何做到这一点的示例:
# Assuming you have set up your Capybara session (e.g., using Selenium or another driver)
image_input = find('input#clickAction')
图像_输入.单击
确保您已使用所选驱动程序正确设置 Capybara,以使其正常工作。