Module: Kirchhoff::CommonInterface

Included in:
Driver, Selenium::WebDriver::Element
Defined in:
lib/kirchhoff/common_interface.rb

Instance Method Summary collapse

Instance Method Details

#find(selector) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/kirchhoff/common_interface.rb', line 3

def find selector
  e = self.find_element(css: selector).tap do
    Kirchhoff::Logger.call :info, "find #{selector}..."
  end

  block_given? ? yield(e) : e
rescue Selenium::WebDriver::Error::NoSuchElementError
  nil
end

#find_text(text) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/kirchhoff/common_interface.rb', line 19

def find_text text
  e = self.find_element({xpath: "//*[text()[contains(.,\"#{text}\")]]"}).tap do
    Kirchhoff::Logger.call :info, "find text '#{text}'..."
  end

  block_given? ? yield(e) : e
rescue Selenium::WebDriver::Error::NoSuchElementError
  nil
end

#multi_find(selector) ⇒ Object



13
14
15
16
17
# File 'lib/kirchhoff/common_interface.rb', line 13

def multi_find selector
  self.find_elements(css: selector).tap do |e|
    Kirchhoff::Logger.call :info, "multi find #{selector}..."
  end
end

#multi_find_text(text) ⇒ Object



29
30
31
32
33
# File 'lib/kirchhoff/common_interface.rb', line 29

def multi_find_text text
  self.find_elements({xpath: "//*[text()[contains(.,\"#{text}\")]]"}).tap do |e|
    Kirchhoff::Logger.call :info, "multi find text '#{text}'..."
  end
end

#to_htmlObject



35
36
37
# File 'lib/kirchhoff/common_interface.rb', line 35

def to_html
  attribute "outerHTML"
end

#to_nokogiriObject



39
40
41
# File 'lib/kirchhoff/common_interface.rb', line 39

def to_nokogiri
  Nokogiri::HTML self.to_html
end