Clicking a Button with Ruby Mechanize

Clicking a button with Ruby Mechanize

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.

Click on button with custom event with Ruby Mechanize

Mechanize doesn't do javascript so button events just get ignored. For that you need a full browser like watir, watir-webdriver, selenium-webdriver, celerity, capybara-webkit or one that I missed.

How can I use mechanize to click button to webscrape a page to get information?

The button you're trying to get mechanize to click is not a "regular" button, it's a bit more dynamic. It uses javascript / ajax to fetch the relevant data when clicked.

Mechanize doesn't render the DOM of a web page nor it provides a way to have javascript interact with the page. Thus it's not suitable for interacting with dynamic pages depending on javascript for their functionality.

For such cases, I'd suggest phantomjs, either standalone or through capybara / poltergeist if you'd prefer interacting with it via ruby.

click button (not in form) with mechanize/nokogiri

You can probably use "watir" insteed. It can mimic the actions (such as clicking, rolling the page) in a browser.



Related Topics



Leave a reply



Submit