Class: Selenium::WebDriver::TargetLocator
- Inherits:
-
Object
- Object
- Selenium::WebDriver::TargetLocator
- Defined in:
- lib/selenium/webdriver/common/target_locator.rb
Instance Method Summary collapse
-
#active_element ⇒ WebDriver::Element
get the active element.
-
#alert ⇒ Object
switches to the currently active modal dialog for this particular driver instance.
-
#default_content ⇒ Object
selects either the first frame on the page, or the main document when a page contains iframes.
-
#frame(id) ⇒ Object
switch to the frame with the given id.
-
#initialize(bridge) ⇒ TargetLocator
constructor
private
A new instance of TargetLocator.
-
#parent_frame ⇒ Object
switch to the parent frame.
-
#window(id) ⇒ Object
switch to the given window handle.
Constructor Details
#initialize(bridge) ⇒ TargetLocator
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of TargetLocator.
25 26 27 |
# File 'lib/selenium/webdriver/common/target_locator.rb', line 25 def initialize(bridge) @bridge = bridge end |
Instance Method Details
#active_element ⇒ WebDriver::Element
get the active element
88 89 90 |
# File 'lib/selenium/webdriver/common/target_locator.rb', line 88 def active_element @bridge.switch_to_active_element end |
#alert ⇒ Object
switches to the currently active modal dialog for this particular driver instance
104 105 106 |
# File 'lib/selenium/webdriver/common/target_locator.rb', line 104 def alert Alert.new(@bridge) end |
#default_content ⇒ Object
selects either the first frame on the page, or the main document when a page contains iframes.
96 97 98 |
# File 'lib/selenium/webdriver/common/target_locator.rb', line 96 def default_content @bridge.switch_to_default_content end |
#frame(id) ⇒ Object
switch to the frame with the given id
33 34 35 |
# File 'lib/selenium/webdriver/common/target_locator.rb', line 33 def frame(id) @bridge.switch_to_frame id end |
#parent_frame ⇒ Object
switch to the parent frame
41 42 43 |
# File 'lib/selenium/webdriver/common/target_locator.rb', line 41 def parent_frame @bridge.switch_to_parent_frame end |
#window(id) ⇒ Object
switch to the given window handle
If given a block, this method will switch back to the original window after block execution.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/selenium/webdriver/common/target_locator.rb', line 55 def window(id) if block_given? original = begin @bridge.window_handle rescue Error::NoSuchWindowError nil end unless @bridge.window_handles.include? id raise Error::NoSuchWindowError, "The specified identifier '#{id}' is not found in the window handle list" end @bridge.switch_to_window id begin returned = yield ensure current_handles = @bridge.window_handles original = current_handles.first unless current_handles.include? original @bridge.switch_to_window original returned end else @bridge.switch_to_window id end end |