如何使用水豚瞄准<input type="image" ....>?

问题描述 投票:0回答:2

这是我观点的一部分......

  <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........'

结束 结束

ruby-on-rails ruby testing capybara capybara-webkit
2个回答
0
投票

0
投票

你可以使用水豚的find方法。您可以根据元素的 id 属性(在本例中为“clickAction”)来定位该元素。以下是如何做到这一点的示例:

# Assuming you have set up your Capybara session (e.g., using Selenium or another driver)

通过 id 查找输入元素

image_input = find('input#clickAction')

对元素执行操作,例如单击它

图像_输入.单击

确保您已使用所选驱动程序正确设置 Capybara,以使其正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.