Module: Watir::PageContainer
- Includes:
- Exception, Win32
- Included in:
- Frame, IE, ModalDialog
- Defined in:
- lib/watir/page-container.rb,
lib/watir/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
-
#html ⇒ Object
The HTML of the current page.
- #set_container(container) ⇒ Object
-
#show_frames ⇒ Object
This method is used to display the available html frames that Internet Explorer currently has loaded.
-
#text ⇒ Object
The text of the current page.
-
#url ⇒ Object
The url of the page object.
Methods included from Win32
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/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 , 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 , m[1] if m end end false end |
#contains_text(target) ⇒ Object
Search the current page for specified text or regexp. Returns the index if the specified text was found. Returns matchdata object if the specified regexp was found.
Deprecated Instead use
IE#text.include? target
or
IE#text.match target
86 87 88 89 90 91 92 93 94 |
# File 'lib/watir/page-container.rb', line 86 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/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 Waiter.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 |
#html ⇒ Object
The HTML of the current page
37 38 39 |
# File 'lib/watir/page-container.rb', line 37 def html page.outerhtml end |
#set_container(container) ⇒ Object
51 52 53 54 |
# File 'lib/watir/page-container.rb', line 51 def set_container container @container = container @page_container = self end |
#show_frames ⇒ Object
This method is used to display the available html frames that Internet Explorer currently has loaded. This method is usually only used for debugging test scripts.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/watir/page-container.rb', line 58 def show_frames if allFrames = document.frames count = allFrames.length puts "there are #{count} frames" for i in 0..count-1 do begin fname = allFrames.item(i).name.to_s puts "frame index: #{i + 1} name: #{fname}" rescue => e if e.to_s.match(/Access is denied/) puts "frame index: #{i + 1} Access Denied, see http://wiki.openqa.org/display/WTR/FAQ#access-denied" end end end else puts "no frames" end end |
#text ⇒ Object
The text of the current page
47 48 49 |
# File 'lib/watir/page-container.rb', line 47 def text page.innertext.strip end |
#url ⇒ Object
The url of the page object.
42 43 44 |
# File 'lib/watir/page-container.rb', line 42 def url page.document.location.href end |