Ruby/Windows Platform/Internet Explorer

Материал из Wiki.crossplatform.ru

Версия от 17:59, 13 сентября 2010; ViGOur (Обсуждение | вклад)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Содержание

Access to Windows Automation is provided by Ruby"s WIN32OLE.

require "win32ole"
web_browser = WIN32OLE.new("InternetExplorer.Application")
web_browser.visible = true
web_browser.navigate("http://www.crossplatform.ru/")



Display your html document in a Internet Explorer

require "win32ole"
html = <<EOF
<html>
<body>
<h3>And now for something</h3>
</body>
</html>
EOF
ie = WIN32OLE.new("InternetExplorer.Application");
ie.left       = 150
ie.top        = 150
ie.height     = 200
ie.width      = 300
ie.menubar    = 0
ie.toolbar    = 0
ie.navigate "about:blank"
ie.visible=TRUE;
ie.document.open
ie.document.write html
ie.document.close
sleep 5
ie.quit



Get parsed html document

require "win32ole"
web_browser = WIN32OLE.new("InternetExplorer.Application")
web_browser.visible = true
web_browser.navigate("http://www.crossplatform.ru/")
while web_browser.ReadyState != 4
  sleep 1
end
puts web_browser.document.getElementById("header").innerHtml.length
puts "Page is loaded"



Load home page with Internet Explorer

require "win32ole" 
ie = WIN32OLE.new("InternetExplorer.Application") 
ie.visible = true 
ie.gohome



make it navigate to a particular page.

require "win32ole" 
ie = WIN32OLE.new("InternetExplorer.Application") 
ie.visible = true 
ie.navigate("http://www.crossplatform.ru")



Open a dialog in Internet Explorer

require "win32ole"
def ieInputBox( msg, default )
  ie = WIN32OLE.new("InternetExplorer.Application");
  ie.visible  = false
  sleep 0.01 while (ie.busy)
  script = ie.Document.Script;
  result = script.prompt(msg,default);
  ie.quit
  result
end
result = ieInputBox( "Please enter your name",
                     "Dave Bowman")
if result
  puts result
else
  puts "User pressed Cancel"
end



uses the ReadyState property to determine when Internet Explorer has successfully finished loading the page.

# If the page is not yet loaded, Ruby sleeps for a second and checks again. 
 
require "win32ole"
web_browser = WIN32OLE.new("InternetExplorer.Application")
web_browser.visible = true
web_browser.navigate("http://www.crossplatform.ru/")
while web_browser.ReadyState != 4
  sleep 1
end
puts "Page is loaded"