Class: OperaWatir::Window
- Includes:
- Deprecated
- Defined in:
- lib/operawatir/window.rb
Instance Attribute Summary collapse
-
#browser ⇒ Object
Returns the value of attribute browser.
Instance Method Summary collapse
-
#back ⇒ Object
Navigates back one step in the browser’s history.
-
#close ⇒ Object
Closes the currently open window.
-
#document ⇒ Element
Finds the root element of the document.
-
#elements ⇒ Collection
Finds all elements in document.
-
#execute_script(js) ⇒ String
(also: #eval_js)
Executes the given JavaScript on the current window.
-
#exists? ⇒ Boolean
Checks if the window is still open.
-
#forward ⇒ Object
Navigates forward one step in the browser’s history.
-
#html ⇒ String
Retrieves the HTML/source code of the currently loaded document.
-
#initialize(browser) ⇒ Object
constructor
Creates a new window in the browser.
- #method_missing(tag, *args) ⇒ Object
-
#refresh ⇒ Object
Refreshes the page.
-
#screenshot(filename = nil) ⇒ Object, String
Creates a Screenshot interface or saves screenshot to specified location if a file path is given.
-
#stop ⇒ Object
Stops the currently loading page.
-
#text ⇒ String
Retrieves the text without the DOM or source code from the currently loaded document.
-
#title ⇒ String
Gets the title of the document.
-
#url ⇒ String
Gets the URL of the document.
-
#url=(url) ⇒ Object
(also: #goto)
Navigates to a new URL.
-
#visual_hash ⇒ String
Returns a visual hash sum of the document.
Constructor Details
#initialize(browser) ⇒ Object
Creates a new window in the browser. Note that Opera does not differentiate between windows and tabs. To directly create a Window object, pass in the Browser.
16 17 18 |
# File 'lib/operawatir/window.rb', line 16 def initialize(browser) self.browser = browser end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(tag, *args) ⇒ Object
183 184 185 186 187 188 |
# File 'lib/operawatir/window.rb', line 183 def method_missing(tag, *args) OperaWatir::Collection.new(self).tap do |c| c.selector.tag_name tag c.add_selector_from_arguments args end end |
Instance Attribute Details
#browser ⇒ Object
Returns the value of attribute browser.
4 5 6 |
# File 'lib/operawatir/window.rb', line 4 def browser @browser end |
Instance Method Details
#back ⇒ Object
Navigates back one step in the browser’s history.
24 25 26 |
# File 'lib/operawatir/window.rb', line 24 def back driver.navigate.back end |
#close ⇒ Object
Closes the currently open window.
39 40 41 |
# File 'lib/operawatir/window.rb', line 39 def close driver.close # FIXME? end |
#document ⇒ Element
Finds the root element of the document. For HTML document, this is the element with the tagName “HTML”.
169 170 171 |
# File 'lib/operawatir/window.rb', line 169 def document find_by_css(':root') end |
#elements ⇒ Collection
Finds all elements in document.
179 180 181 |
# File 'lib/operawatir/window.rb', line 179 def elements find_by_tag('*') end |
#execute_script(js) ⇒ String Also known as: eval_js
Executes the given JavaScript on the current window.
111 112 113 |
# File 'lib/operawatir/window.rb', line 111 def execute_script(js) object = driver.executeScript(js, [].to_java(:string)) end |
#exists? ⇒ Boolean
Checks if the window is still open. True if the window is still present, false otherwise.
102 103 104 105 |
# File 'lib/operawatir/window.rb', line 102 def exists? # TODO: Expose window querying from driver url != '' end |
#forward ⇒ Object
Navigates forward one step in the browser’s history.
29 30 31 |
# File 'lib/operawatir/window.rb', line 29 def forward driver.navigate.forward end |
#html ⇒ String
Retrieves the HTML/source code of the currently loaded document.
94 95 96 |
# File 'lib/operawatir/window.rb', line 94 def html driver.getPageSource end |
#refresh ⇒ Object
Refreshes the page.
44 45 46 |
# File 'lib/operawatir/window.rb', line 44 def refresh driver.navigate.refresh end |
#screenshot(filename = nil) ⇒ Object, String
Creates a Screenshot interface or saves screenshot to specified location if a file path is given.
132 133 134 135 136 |
# File 'lib/operawatir/window.rb', line 132 def screenshot(filename=nil) # TODO: This should call document.screenshot instead, but that # requires a generic ScreenShotReply interface in OperaDriver. filename.nil? ? OperaWatir::Screenshot.new(self) : OperaWatir::Screenshot.new(self).save(filename) end |
#stop ⇒ Object
Stops the currently loading page.
34 35 36 |
# File 'lib/operawatir/window.rb', line 34 def stop driver.stop end |
#text ⇒ String
Retrieves the text without the DOM or source code from the currently loaded document.
87 88 89 |
# File 'lib/operawatir/window.rb', line 87 def text document.text end |
#title ⇒ String
Gets the title of the document.
51 52 53 |
# File 'lib/operawatir/window.rb', line 51 def title driver.getTitle end |
#url ⇒ String
Gets the URL of the document.
61 62 63 |
# File 'lib/operawatir/window.rb', line 61 def url driver.getCurrentUrl end |
#url=(url) ⇒ Object Also known as: goto
Navigates to a new URL.
69 70 71 |
# File 'lib/operawatir/window.rb', line 69 def url=(url) driver.navigate.to(url) end |
#visual_hash ⇒ String
Returns a visual hash sum of the document. It takes a screenshot of the page and generates an MD5 hash sum of it.
145 146 147 |
# File 'lib/operawatir/window.rb', line 145 def visual_hash document.visual_hash end |