Class: Watir::Window
Instance Method Summary
collapse
#wait_until_present, #wait_while_present, #when_present
Constructor Details
#initialize(driver, selector) ⇒ Window
Returns a new instance of Window.
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/watir-webdriver/window.rb', line 5
def initialize(driver, selector)
@driver = driver
@selector = selector
if selector.empty?
@handle = driver.window_handle
elsif selector.has_key? :handle
@handle = selector.delete :handle
else
unless selector.keys.all? { |k| [:title, :url, :index].include? k }
raise ArgumentError, "invalid window selector: #{selector.inspect}"
end
end
end
|
Instance Method Details
#==(other) ⇒ Object
Also known as:
eql?
65
66
67
68
69
|
# File 'lib/watir-webdriver/window.rb', line 65
def ==(other)
return false unless other.kind_of?(self.class)
handle == other.handle
end
|
80
81
82
|
# File 'lib/watir-webdriver/window.rb', line 80
def close
use { @driver.close }
end
|
#current? ⇒ Boolean
76
77
78
|
# File 'lib/watir-webdriver/window.rb', line 76
def current?
@driver.window_handle == handle
end
|
72
73
74
|
# File 'lib/watir-webdriver/window.rb', line 72
def hash
handle.hash ^ self.class.hash
end
|
20
21
22
|
# File 'lib/watir-webdriver/window.rb', line 20
def inspect
'#<%s:0x%x located=%s>' % [self.class, hash*2, !!@handle]
end
|
#move_to(x, y) ⇒ Object
45
46
47
48
49
50
|
# File 'lib/watir-webdriver/window.rb', line 45
def move_to(x, y)
point = Selenium::WebDriver::Point.new(x, y)
use { @driver.manage.window.position = point }
point
end
|
31
32
33
34
35
36
|
# File 'lib/watir-webdriver/window.rb', line 31
def position
pos = nil
use { pos = @driver.manage.window.position }
pos
end
|
#present? ⇒ Boolean
59
60
61
62
63
|
# File 'lib/watir-webdriver/window.rb', line 59
def present?
@handle = nil
exists?
end
|
#resize_to(width, height) ⇒ Object
38
39
40
41
42
43
|
# File 'lib/watir-webdriver/window.rb', line 38
def resize_to(width, height)
dimension = Selenium::WebDriver::Dimension.new(width, height)
use { @driver.manage.window.size = dimension }
dimension
end
|
24
25
26
27
28
29
|
# File 'lib/watir-webdriver/window.rb', line 24
def size
size = nil
use { size = @driver.manage.window.size }
size
end
|
84
85
86
87
88
89
|
# File 'lib/watir-webdriver/window.rb', line 84
def title
title = nil
use { title = @driver.title }
title
end
|
91
92
93
94
95
96
|
# File 'lib/watir-webdriver/window.rb', line 91
def url
url = nil
use { url = @driver.current_url }
url
end
|
#use(&blk) ⇒ Object
98
99
100
101
|
# File 'lib/watir-webdriver/window.rb', line 98
def use(&blk)
@driver.switch_to.window(handle, &blk)
self
end
|