Ruby watir to get html pages

I looked at examples on these pages.

http://watir.com/examples/ http://wiki.openqa.org/display/WTR/Examples

I still don't see a simple example of getting an html page.

browser = Watir::Browser.new browser.goto 'mysite.com' 

I tried

 puts browser.text 

It doesn't seem to work.

thanks

+6
source share
4 answers

This should do it:

 puts browser.html 
+21
source

IE8, Ruby 1.9.3, Watir 3.0, WindowsXP

I need to capture text in a cell with id = "numberCovered".

 <table cellpadding="0" cellspacing="0" class="thisThemeBodyColor"><tr style="height:22px;"><td id="numberCoveredlabel" style="cursor:default;" class="smallHeadingBlack" width="200">Number of individuals to be covered</td><td id="numberCovered" class="smallHeadingBlack" style="font-weight:bold;">1</td><input type="hidden" name="numberCovered" tooltip="" value="1" onpropertychange="variableAsTextChanged(this);"/></tr><tr><td id="numberSpouseslabel" style="cursor:default;" class="smallHeadingBlack" width="200">Number of spouses to be covered</td><td id="numberSpouses" class="smallHeadingBlack" style="font-weight:bold;">0</td><input type="hidden" name="numberSpouses" tooltip="" value="0" onpropertychange="variableAsTextChanged(this);"/></tr></table> 

As already mentioned, the initial dump of the original page is sometimes nice, because you cannot find the appropriate Watir built-in method.

- Update-- The above $ browser.html spewed out empty lines, but this seems to work:

 require 'nokogiri' page_html = Nokogiri::HTML.parse($browser.html) entry = page_html.css('td[id=numberCovered]') 
+1
source
 puts browser.html 

Will return all html, if you only want to print active objects, you can use:

 puts browser.show_active 

Similarly, if you want links to be printed, you can use:

 puts browser.show_links 
+1
source

puts browser.html will return all the objects on the page. If you want only active objects, you can use puts browser.show_active same way, if you want only links displayed, you can use puts browser.show_links , which displays all the links on the page.

0
source

Source: https://habr.com/ru/post/908567/


All Articles