Class: Selenium::WebDriver::TargetLocator

Inherits:
Object
  • Object
show all
Defined in:
lib/selenium/webdriver/common/target_locator.rb

Instance Method Summary collapse

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.



26
27
28
# File 'lib/selenium/webdriver/common/target_locator.rb', line 26

def initialize(bridge)
  @bridge = bridge
end

Instance Method Details

#active_elementWebDriver::Element

get the active element

Returns:



85
86
87
# File 'lib/selenium/webdriver/common/target_locator.rb', line 85

def active_element
  @bridge.switchToActiveElement
end

#alertObject

switches to the currently active modal dialog for this particular driver instance



101
102
103
# File 'lib/selenium/webdriver/common/target_locator.rb', line 101

def alert
  Alert.new(@bridge)
end

#default_contentObject

selects either the first frame on the page, or the main document when a page contains iframes.



93
94
95
# File 'lib/selenium/webdriver/common/target_locator.rb', line 93

def default_content
  @bridge.switchToDefaultContent
end

#frame(id) ⇒ Object

switch to the frame with the given id



34
35
36
# File 'lib/selenium/webdriver/common/target_locator.rb', line 34

def frame(id)
  @bridge.switchToFrame id
end

#parent_frameObject

switch to the parent frame



42
43
44
# File 'lib/selenium/webdriver/common/target_locator.rb', line 42

def parent_frame
  @bridge.switchToParentFrame
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.

Parameters:

  • id

    A window handle, obtained through Driver#window_handles



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/selenium/webdriver/common/target_locator.rb', line 56

def window(id)
  if block_given?
    original = begin
      @bridge.getCurrentWindowHandle
    rescue Error::NoSuchWindowError
      nil
    end

    @bridge.switchToWindow id

    begin
      returned = yield
    ensure
      current_handles = @bridge.getWindowHandles
      original = current_handles.first unless current_handles.include? original
      @bridge.switchToWindow original
      returned
    end
  else
    @bridge.switchToWindow id
  end
end