Module: OnlyofficeWebdriverWrapper::GetTextMethods

Included in:
WebDriver
Defined in:
lib/onlyoffice_webdriver_wrapper/webdriver/get_text_methods.rb

Overview

Method to get text

Instance Method Summary collapse

Instance Method Details

#get_text(xpath_name, wait_until_visible = true) ⇒ String

Get text of current element

Parameters:

  • xpath_name (String)

    name of xpath

  • wait_until_visible (Boolean) (defaults to: true)

    wait until element visible

Returns:

  • (String)

    result string



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/get_text_methods.rb', line 10

def get_text(xpath_name, wait_until_visible = true)
  wait_until_element_visible(xpath_name) if wait_until_visible

  element = get_element(xpath_name)
  webdriver_error("get_text(#{xpath_name}, #{wait_until_visible}) not found element by xpath") if element.nil?
  if element.tag_name == 'input' || element.tag_name == 'textarea'
    element.attribute('value')
  else
    element.text
  end
end

#get_text_array(array_elements) ⇒ Array<String>

Get text from all elements with specified xpath

Parameters:

  • array_elements (String)

    xpath of elements

Returns:

  • (Array<String>)

    values of elements



34
35
36
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/get_text_methods.rb', line 34

def get_text_array(array_elements)
  get_elements(array_elements).map { |current_element| get_text(current_element) }
end

#get_text_by_js(xpath) ⇒ String

Get text in object by xpath

Parameters:

  • xpath (String)

    xpath to get text

Returns:

  • (String)

    text in xpath



25
26
27
28
29
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/get_text_methods.rb', line 25

def get_text_by_js(xpath)
  text = execute_javascript("return #{dom_element_by_xpath(xpath)}.textContent")
  text = execute_javascript("return #{dom_element_by_xpath(xpath)}.value") if text.empty?
  text
end

#get_text_of_several_elements(xpath_several_elements) ⇒ Array<String>

Get text from several elements This method filter out all elements with empty text

Parameters:

  • xpath_several_elements (String)

    to find objects

Returns:

  • (Array<String>)

    text of those elements



42
43
44
45
46
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/get_text_methods.rb', line 42

def get_text_of_several_elements(xpath_several_elements)
  @driver.find_elements(:xpath, xpath_several_elements).filter_map do |element|
    element.text unless element.text == ''
  end
end