¿Automatizar el navegador sin una ventana real del navegador?
Frecuentes
Visto 548 veces
1
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
3 Respuestas
-1
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
Respondido 28 ago 12, 17:08
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas ruby capybara mechanize watir or haz tu propia pregunta.
Why does 'not having a monitor attached' mean that you can't use a browser-driver? It's pretty common to have such tests running in continuous integration environments (i.e. on headless servers) - Jon M
Well now that I think about it, it really should be possible (normal Windows computer does not need physical monitor to run any applications...) Server-maintaining guy (not me) just said, "there is no desktop so any windowed application won't work"... Maybe he was wrong, I have to discuss about this more with him... - apk
Exactly what I thought! If you have a working solution then you may as well use it if possible, and I've done a lot of testing with browsers on Windows-based continuous integration servers which run without a desktop, it's certainly possible. - Jon M