Class: GogoDriver
- Inherits:
-
Object
show all
- Defined in:
- lib/gogo_driver.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of GogoDriver.
6
7
8
|
# File 'lib/gogo_driver.rb', line 6
def initialize
@driver = Selenium::WebDriver.for(:chrome)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
46
47
48
|
# File 'lib/gogo_driver.rb', line 46
def method_missing(method, *args, &block)
@driver.respond_to?(method) ? @driver.send(method, *args, &block) : super
end
|
Instance Attribute Details
#driver ⇒ Object
Returns the value of attribute driver.
4
5
6
|
# File 'lib/gogo_driver.rb', line 4
def driver
@driver
end
|
Instance Method Details
#click(selector) ⇒ Object
38
39
40
|
# File 'lib/gogo_driver.rb', line 38
def click(selector)
has?(selector) ? find(selector).click : false
end
|
#find(selector) ⇒ Object
18
19
20
|
# File 'lib/gogo_driver.rb', line 18
def find(selector)
@driver.find_element(css: selector)
end
|
#finds(selector) ⇒ Object
22
23
24
|
# File 'lib/gogo_driver.rb', line 22
def finds(selector)
@driver.find_elements(css: selector)
end
|
#go(url) ⇒ Object
10
11
12
|
# File 'lib/gogo_driver.rb', line 10
def go(url)
@driver.navigate.to(url)
end
|
#has?(selector) ⇒ Boolean
26
27
28
29
30
|
# File 'lib/gogo_driver.rb', line 26
def has?(selector)
!!find(selector)
rescue Selenium::WebDriver::Error::NoSuchElementError
false
end
|
#has_text?(text) ⇒ Boolean
32
33
34
35
36
|
# File 'lib/gogo_driver.rb', line 32
def has_text?(text)
!!@driver.find_element({xpath: "//*[text()[contains(.,\"#{text}\")]]"})
rescue Selenium::WebDriver::Error::NoSuchElementError
false
end
|
#reload ⇒ Object
14
15
16
|
# File 'lib/gogo_driver.rb', line 14
def reload
@driver.navigate.refresh
end
|
#submit ⇒ Object
42
43
44
|
# File 'lib/gogo_driver.rb', line 42
def submit
$focus.submit if $focus
end
|