Class: Aranha::Selenium::Session
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Aranha::Selenium::Session
- Defined in:
- lib/aranha/selenium/session.rb
Defined Under Namespace
Classes: Downloads
Instance Attribute Summary collapse
-
#downloads ⇒ Object
readonly
Returns the value of attribute downloads.
-
#wait ⇒ Object
readonly
Returns the value of attribute wait.
Instance Method Summary collapse
- #current_source ⇒ Object
- #find_or_not_element(find_element_args) ⇒ Object
-
#initialize(options = {}) ⇒ Session
constructor
A new instance of Session.
- #wait_for_click(find_element_args) ⇒ Object
- #wait_for_download ⇒ Object
- #wait_for_element(find_element_args) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Session
Returns a new instance of Session.
10 11 12 13 14 15 16 17 18 |
# File 'lib/aranha/selenium/session.rb', line 10 def initialize( = {}) @downloads = Downloads.new @wait = ::Selenium::WebDriver::Wait.new(timeout: 15) super( ::Aranha::Selenium::DriverFactory.create_driver( .merge(download_dir: @downloads.dir) ) ) end |
Instance Attribute Details
#downloads ⇒ Object (readonly)
Returns the value of attribute downloads.
8 9 10 |
# File 'lib/aranha/selenium/session.rb', line 8 def downloads @downloads end |
#wait ⇒ Object (readonly)
Returns the value of attribute wait.
8 9 10 |
# File 'lib/aranha/selenium/session.rb', line 8 def wait @wait end |
Instance Method Details
#current_source ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/aranha/selenium/session.rb', line 47 def current_source element = find_element(xpath: '/html[1]') raise 'Root element not found' unless element s = element.attribute('innerHTML') "<html>\n#{s}\n</html>\n" end |
#find_or_not_element(find_element_args) ⇒ Object
20 21 22 23 |
# File 'lib/aranha/selenium/session.rb', line 20 def find_or_not_element(find_element_args) r = find_elements(find_element_args) r.any? ? r.first : nil end |
#wait_for_click(find_element_args) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/aranha/selenium/session.rb', line 25 def wait_for_click(find_element_args) wait.until do element = find_element(find_element_args) element ? element_click(element) : nil end end |
#wait_for_download ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/aranha/selenium/session.rb', line 36 def wait_for_download initial_downloads = downloads.current yield new_downloads = [] wait.until do new_downloads = downloads.current - initial_downloads new_downloads.any? end new_downloads.first end |
#wait_for_element(find_element_args) ⇒ Object
32 33 34 |
# File 'lib/aranha/selenium/session.rb', line 32 def wait_for_element(find_element_args) wait.until { find_element(find_element_args) } end |