Class: Selenium::WebDriver::Window

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

Instance Method Summary collapse

Constructor Details

#initialize(bridge) ⇒ Window

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 Window.



33
34
35
# File 'lib/selenium/webdriver/common/window.rb', line 33

def initialize(bridge)
  @bridge = bridge
end

Instance Method Details

#maximizeObject

Maximize the current window



116
117
118
# File 'lib/selenium/webdriver/common/window.rb', line 116

def maximize
  @bridge.maximizeWindow
end

#move_to(x, y) ⇒ Object

Equivalent to #position=, but accepts x and y arguments.

Examples:


driver.manage.window.move_to(300, 400)


108
109
110
# File 'lib/selenium/webdriver/common/window.rb', line 108

def move_to(x, y)
  @bridge.setWindowPosition Integer(x), Integer(y)
end

#positionSelenium::WebDriver::Point

Get the position of the current window.

Returns:



83
84
85
# File 'lib/selenium/webdriver/common/window.rb', line 83

def position
  @bridge.getWindowPosition
end

#position=(point) ⇒ Object

Move the current window to the given position.

Parameters:



68
69
70
71
72
73
74
75
# File 'lib/selenium/webdriver/common/window.rb', line 68

def position=(point)
  unless point.respond_to?(:x) && point.respond_to?(:y)
    raise ArgumentError, "expected #{point.inspect}:#{point.class}" +
                          " to respond to #x and #y"
  end

  @bridge.setWindowPosition point.x, point.y
end

#resize_to(width, height) ⇒ Object

Equivalent to #size=, but accepts width and height arguments.

Examples:

Maximize the window.


max_width, max_height = driver.execute_script("return [window.screen.availWidth, window.screen.availHeight];")
driver.manage.window.resize_to(max_width, max_height)


96
97
98
# File 'lib/selenium/webdriver/common/window.rb', line 96

def resize_to(width, height)
  @bridge.setWindowSize Integer(width), Integer(height)
end

#sizeSelenium::WebDriver::Dimension

Get the size of the current window.

Returns:



58
59
60
# File 'lib/selenium/webdriver/common/window.rb', line 58

def size
  @bridge.getWindowSize
end

#size=(dimension) ⇒ Object

Resize the current window to the given dimension.

Parameters:



43
44
45
46
47
48
49
50
# File 'lib/selenium/webdriver/common/window.rb', line 43

def size=(dimension)
  unless dimension.respond_to?(:width) && dimension.respond_to?(:height)
    raise ArgumentError, "expected #{dimension.inspect}:#{dimension.class}" +
                          " to respond to #width and #height"
  end

  @bridge.setWindowSize dimension.width, dimension.height
end