Module: Watir::PageContainer
- Included in:
- Frame, IE, ModalDialog
- Defined in:
- lib/watir-classic/page-container.rb,
lib/watir-classic/contrib/enabled_popup.rb
Overview
A PageContainer contains an HTML Document. In other words, it is a what JavaScript calls a Window.
Constant Summary
Constants included from Win32
Win32::FindWindowEx, Win32::GW_CHILD, Win32::GW_ENABLEDPOPUP, Win32::GW_HWNDFIRST, Win32::GW_HWNDLAST, Win32::GW_HWNDNEXT, Win32::GW_HWNDPREV, Win32::GW_MAX, Win32::GW_OWNER, Win32::GetUnknown, Win32::GetWindow, Win32::IsWindow, Win32::User32
Instance Method Summary collapse
-
#check_for_http_error ⇒ Object
This method checks the currently displayed page for http errors, 404, 500 etc It gets called internally by the wait method, so a user does not need to call it explicitly.
-
#contains_text(target) ⇒ Object
Search the current page for specified text or regexp.
- #enabled_popup(timeout = 4) ⇒ Object
-
#execute_script(source) ⇒ Object
Execute the given JavaScript string.
-
#html ⇒ Object
The HTML of the current page.
- #set_container(container) ⇒ Object
-
#text ⇒ Object
The text of the current page.
-
#url ⇒ Object
The url of the page object.
Methods included from Win32
Methods included from Exception
Instance Method Details
#check_for_http_error ⇒ Object
This method checks the currently displayed page for http errors, 404, 500 etc It gets called internally by the wait method, so a user does not need to call it explicitly
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/watir-classic/page-container.rb', line 10 def check_for_http_error # check for IE7 n = self.document.invoke('parentWindow').navigator.appVersion m=/MSIE\s(.*?);/.match( n ) if m and m[1] =='7.0' if m = /HTTP (\d\d\d.*)/.match( self.title ) raise NavigationException, m[1] end else # assume its IE6 url = self.document.location.href if /shdoclc.dll/.match(url) m = /id=IEText.*?>(.*?)</i.match(self.html) raise NavigationException, m[1] if m end end false end |
#contains_text(target) ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/watir-classic/page-container.rb', line 82 def contains_text(target) if target.kind_of? Regexp self.text.match(target) elsif target.kind_of? String self.text.index(target) else raise ArgumentError, "Argument #{target} should be a string or regexp." end end |
#enabled_popup(timeout = 4) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/watir-classic/contrib/enabled_popup.rb', line 6 def enabled_popup(timeout=4) # Use handle of our parent window to see if we have any currently # enabled popup. hwnd_modal = 0 Wait.until(timeout) do hwnd_modal, arr = GetWindow.call(hwnd, GW_ENABLEDPOPUP) hwnd_modal > 0 end # use hwnd() method to find the IE or Container hwnd (overriden by IE) if hwnd_modal == hwnd() || 0 == hwnd_modal hwnd_modal = nil end hwnd_modal end |
#execute_script(source) ⇒ Object
Execute the given JavaScript string
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/watir-classic/page-container.rb', line 37 def execute_script(source) result = nil begin source = with_json2_if_needed source result = document.parentWindow.eval(source) rescue WIN32OLERuntimeError, NoMethodError #if eval fails we need to use execScript(source.to_s) which does not return a value, hence the workaround escaped_src = source.gsub(/\r?\n/, "\\n").gsub("'", "\\\\'") wrapper = "_watir_helper_div_#{::Time.now.to_i + ::Time.now.usec}" cmd = "var e = document.createElement('DIV'); e.style.display='none'; e.id='#{wrapper}'; e.innerHTML = eval('#{escaped_src}'); document.body.appendChild(e);" document.parentWindow.execScript(cmd) result = document.getElementById(wrapper).innerHTML end Yajl::Parser.parse(result) rescue nil end |
#html ⇒ Object
The HTML of the current page
54 55 56 |
# File 'lib/watir-classic/page-container.rb', line 54 def html page.outerhtml end |
#set_container(container) ⇒ Object
68 69 70 71 |
# File 'lib/watir-classic/page-container.rb', line 68 def set_container container @container = container @page_container = self end |
#text ⇒ Object
The text of the current page
64 65 66 |
# File 'lib/watir-classic/page-container.rb', line 64 def text page.innertext.strip end |
#url ⇒ Object
The url of the page object.
59 60 61 |
# File 'lib/watir-classic/page-container.rb', line 59 def url page.document.location.href end |