简体   繁体   English

Nokogiri没有从Watir加载“浏览器”

[英]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'

browser.link(:text, 'Combined Employee Performance Report').click

today = Date.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'
btn.exists?
btn.click

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

When I try to parse browser , the variable that Watir is using for the site URI, it gives me a blank HTML page. 当我尝试解析browser ,Watir用于网站URI的变量给我一个空白的HTML页面。

Problem 问题

When you do 当你做

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

You are asking Nokogiri to parse the string 'browser'. 您要让Nokogiri解析字符串“浏览器”。

Solution

What you actually want to parse is the html in the browser. 您实际上要解析的是浏览器中的html。

To get the browser's html, you do: 要获取浏览器的html,请执行以下操作:

browser.html

So to parse it, you would do: 因此,要解析它,您可以这样做:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM