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.



27
28
29
# File 'lib/selenium/webdriver/common/window.rb', line 27

def initialize(bridge)
  @bridge = bridge
end

Instance Method Details

#full_screenObject

Make current window full screen



154
155
156
# File 'lib/selenium/webdriver/common/window.rb', line 154

def full_screen
  @bridge.full_screen_window
end

#maximizeObject

Maximize the current window



138
139
140
# File 'lib/selenium/webdriver/common/window.rb', line 138

def maximize
  @bridge.maximize_window
end

#minimizeObject

Minimize the current window



146
147
148
# File 'lib/selenium/webdriver/common/window.rb', line 146

def minimize
  @bridge.minimize_window
end

#move_to(x, y) ⇒ Object

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

Examples:


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


130
131
132
# File 'lib/selenium/webdriver/common/window.rb', line 130

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

#positionSelenium::WebDriver::Point

Get the position of the current window.

Returns:



77
78
79
# File 'lib/selenium/webdriver/common/window.rb', line 77

def position
  @bridge.window_position
end

#position=(point) ⇒ Object

Move the current window to the given position.

Parameters:



62
63
64
65
66
67
68
69
# File 'lib/selenium/webdriver/common/window.rb', line 62

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.reposition_window point.x, point.y
end

#rectSelenium::WebDriver::Rectangle

Get the rect of the current window.

Returns:



105
106
107
# File 'lib/selenium/webdriver/common/window.rb', line 105

def rect
  @bridge.window_rect
end

#rect=(rectangle) ⇒ Object

Sets the current window rect to the given point and position.

Parameters:



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/selenium/webdriver/common/window.rb', line 87

def rect=(rectangle)
  unless %w[x y width height].all? { |val| rectangle.respond_to? val }
    raise ArgumentError, "expected #{rectangle.inspect}:#{rectangle.class} " \
                         'to respond to #x, #y, #width, and #height'
  end

  @bridge.set_window_rect(x: rectangle.x,
                          y: rectangle.y,
                          width: rectangle.width,
                          height: rectangle.height)
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)


118
119
120
# File 'lib/selenium/webdriver/common/window.rb', line 118

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

#sizeSelenium::WebDriver::Dimension

Get the size of the current window.

Returns:



52
53
54
# File 'lib/selenium/webdriver/common/window.rb', line 52

def size
  @bridge.window_size
end

#size=(dimension) ⇒ Object

Resize the current window to the given dimension.

Parameters:



37
38
39
40
41
42
43
44
# File 'lib/selenium/webdriver/common/window.rb', line 37

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.resize_window dimension.width, dimension.height
end