Clicking a button with Ruby Mechanize

不羁的心 提交于 2019-11-29 03:34:54

It is not a link, it is a button. What you need to do is look for the form (for example, with form_with) and then look for the ImageButton and submit it.

I struggled with this too, especially since my form had multiple buttons.

There are multiple ways to submit a form (with many using a 'form_with' block), but this helped me:

# get the form
form = agent.page.form_with(:name => "my-form")
# get the button you want from the form
button = form.button_with(:value => "Search")
# submit the form using that button
agent.submit(form, button)

See more info here

Also, make sure you upgrade to the latest mechanize. I was using mechanize 1.x, which was giving me "undefined method" errors for the code above.

button = form.button_with(value: 'Search')
form.click_button(button)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!