Class: GogoDriver
- Inherits:
-
Object
show all
- Defined in:
- lib/gogo_driver.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(browser = :chrome) ⇒ GogoDriver
Returns a new instance of GogoDriver.
6
7
8
|
# File 'lib/gogo_driver.rb', line 6
def initialize(browser=:chrome)
@driver = Selenium::WebDriver.for(browser)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
58
59
60
|
# File 'lib/gogo_driver.rb', line 58
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
48
49
50
51
|
# File 'lib/gogo_driver.rb', line 48
def click(selector)
logging "[CLICK] #{selector}..."
has?(selector) ? find(selector).click : false
end
|
#find(selector) ⇒ Object
19
20
21
22
|
# File 'lib/gogo_driver.rb', line 19
def find(selector)
logging "[FIND] #{selector}..."
@driver.find_element(css: selector)
end
|
#finds(selector) ⇒ Object
32
33
34
|
# File 'lib/gogo_driver.rb', line 32
def finds(selector)
@driver.find_elements(css: selector)
end
|
#go(url) ⇒ Object
10
11
12
13
|
# File 'lib/gogo_driver.rb', line 10
def go(url)
logging "[VISITE] #{url}..."
@driver.navigate.to(url)
end
|
#has?(selector) ⇒ Boolean
36
37
38
39
40
|
# File 'lib/gogo_driver.rb', line 36
def has?(selector)
!!find(selector)
rescue Selenium::WebDriver::Error::NoSuchElementError
false
end
|
#has_text?(text) ⇒ Boolean
42
43
44
45
46
|
# File 'lib/gogo_driver.rb', line 42
def has_text?(text)
!!@driver.find_element({xpath: "//*[text()[contains(.,\"#{text}\")]]"})
rescue Selenium::WebDriver::Error::NoSuchElementError
false
end
|
#reload ⇒ Object
15
16
17
|
# File 'lib/gogo_driver.rb', line 15
def reload
@driver.navigate.refresh
end
|
25
26
27
28
29
30
|
# File 'lib/gogo_driver.rb', line 25
def scroll(selector)
logging "[SCROLL] #{selector}..."
element = find(selector)
@driver.driver.execute_script "window.scrollTo(#{element.location.x},#{element.location.y})"
element
end
|
#submit ⇒ Object
53
54
55
56
|
# File 'lib/gogo_driver.rb', line 53
def submit
logging "[SUBMIT] ..."
$focus.submit if $focus
end
|