ghal ghal - 1 year ago 72
Ruby Question

Nokogiri is not loading "browser" from Watir

I have this so far:

require 'watir-webdriver'
require 'date'
require 'nokogiri'

browser = Watir::Browser.start 'https://example/ViewReport.aspx', 'Combined Employee Performance Report').click

today =
yesterday = today.prev_day.strftime('%m' '%d' '%Y')

t = browser.text_field :id => 'UC255_txtStart'
t.set yesterday

t = browser.text_field :id => 'UC255_txtEnd'
t.set yesterday

btn = browser.button :value, 'Run Report'

page = Nokogiri::HTML.parse('browser')
links = page.css("a")
puts links.length

When I try to parse
, the variable that Watir is using for the site URI, it gives me a blank HTML page.

Answer Source


When you do

page = Nokogiri::HTML.parse('browser')

You are asking Nokogiri to parse the string 'browser'.


What you actually want to parse is the html in the browser.

To get the browser's html, you do:


So to parse it, you would do:

page = Nokogiri::HTML.parse(browser.html)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download