问题
clicking a text agent.click(page.link_with(:text => 'some_text')
with mechainze is piece of cake. How to click an image with mechanize?
回答1:
It is rather similar. You just need to grab one of the attributes of your image. have a look below..:
agent.click(page.image_with(:alt=> 'your image')
回答2:
Clicking on a pure HTML image will typically have no effect. If the image has an onclick
handler, you will not be able to click on it with Mechanize as it does not support javascript.
You may want to use something like Capybara with the Webkit, PhantomJS or Selenium driver instead.
来源:https://stackoverflow.com/questions/11895973/clicking-image-with-mechanize