Class: Selenium::WebDriver::TargetLocator
Relationships & Source Files | |
Inherits: | Object |
Defined in: | rb/lib/selenium/webdriver/common/target_locator.rb |
Class Method Summary
- .new(bridge) ⇒ TargetLocator constructor Internal use only Internal use only
Instance Method Summary
-
#active_element ⇒ WebDriver::Element
get the active element.
-
#alert
switches to the currently active modal dialog for this particular driver instance.
-
#default_content
selects either the first frame on the page, or the main document when a page contains iframes.
-
#frame(id)
switch to the frame with the given id.
-
#new_window(type = :window)
steep:ignore:start.
-
#parent_frame
switch to the parent frame.
-
#window(id)
switch to the given window handle.
Constructor Details
.new(bridge) ⇒ TargetLocator
This method is for internal use only.
# File 'rb/lib/selenium/webdriver/common/target_locator.rb', line 27
def initialize(bridge) @bridge = bridge end
Instance Method Details
#active_element ⇒ WebDriver::Element
get the active element
# File 'rb/lib/selenium/webdriver/common/target_locator.rb', line 118
def active_element @bridge.switch_to_active_element end
#alert
switches to the currently active modal dialog for this particular driver instance
#default_content
selects either the first frame on the page, or the main document when a page contains iframes.
# File 'rb/lib/selenium/webdriver/common/target_locator.rb', line 126
def default_content @bridge.switch_to_default_content end
#frame(id)
switch to the frame with the given id
# File 'rb/lib/selenium/webdriver/common/target_locator.rb', line 35
def frame(id) @bridge.switch_to_frame id end
#new_window(type = :window)
steep:ignore:start
# File 'rb/lib/selenium/webdriver/common/target_locator.rb', line 54
def new_window(type = :window) raise ArgumentError, "Valid types are :tab and :window, received: #{type.inspect}" unless %i[window tab].include?(type) handle = @bridge.new_window(type)['handle'] if block_given? execute_and_close = proc do yield(self) begin @bridge.close rescue Error::NoSuchWindowError # window already closed end end window(handle, &execute_and_close) else window(handle) end end
#parent_frame
switch to the parent frame
# File 'rb/lib/selenium/webdriver/common/target_locator.rb', line 43
def parent_frame @bridge.switch_to_parent_frame end
#window(id)
switch to the given window handle
If given a block, this method will switch back to the original window after block execution.
# File 'rb/lib/selenium/webdriver/common/target_locator.rb', line 86
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 yield ensure current_handles = @bridge.window_handles original = current_handles.first unless current_handles.include? original @bridge.switch_to_window original end else @bridge.switch_to_window id end end