I need to do an automated script that fills two text fields and clicks a button on a web page, and stores all resulting text to a string variable.
I know how to do this with Watir, but the problem is that this script will be running on a Windows server (with no physical monitor attached).
So this needs some kind of "emulated browser" without actual browser window... I have never before done anything like this, but after google search I think that Ruby gems "mechanize" or "capybara" might be able to do the trick.
But because I don't have any experience with either capybara or mehcanize, I'm asking a little help here...
Here is what I'm trying to do, written in Watir code. I would really appreciate it if someone could tell me how to do the same thing with either "mechanize" or "capybara". Or, if there is some other way to do this, all suggestion are welcomed:
require "watir" ie = Watir::Browser.new ie.goto "http://www.vero.fi/vere/Tarkistus/VeronumeronTarkistus.aspx/" ie.text_field(:id, "tbNimi").set "John Smith" ie.text_field(:id, "tbVerotunnus").set "123456789012" ie.button(:id, "btnHae").click info = ie.text
preguntado el 28 de agosto de 12 a las 13:08
yo suelo PhantomJS for this (with the Capybara driver duende). It runs a headless WebKit (Safari and Chrome's browser engine) and Capybara tells it what to do. It's the simplest-to-setup implementation of this concept that I've found.
El código se vería así:
visit "http://www.vero.fi/vere/Tarkistus/VeronumeronTarkistus.aspx/" fill_in "tbNimi", :with => "John Smith" fill_in "tbVerotunnus", :with => "123456789012" click_on "btnHae" info = page.html