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
Script to Run Against Stdin If No Arg; Otherwise Input File =Argv[0]
Using Activemodel::Serializer in Rails - JSON Data Differs Between JSON and Index Response
Expected #Count to Have Changed by 1, But Was Not Given a Block
Ruby Conditional-Assignment and Private Methods
Ruby: Is Variable Is Object in Ruby
Ruby Ssl with Twitter Failed on Cert Openssl Issue on Windows 7
Error Installing Ruby 2.6.7 on MAC Os - How to Resolve
Uninitialized Constant > Actioncable::Server::Configuration::Applicationcable
How to Round a Float to a Specified Number of Significant Digits in Ruby
How to Extend Redcarpet to Support Auto Linking User Mentions
Uploading a File to a Website with Ruby/Rails
How Can One Set Property Values When Initializing an Object in Ruby
Where to Put a Before_Filter Shared Between Multiple Controllers
What Are Symbols and How Do We Use Them
What Is the Purpose of the Enumerator Class in Ruby