Module: OnlyofficeWebdriverWrapper::SelectListMethods

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

Overview

Method to work with select list

Instance Method Summary collapse

Instance Method Details

#get_all_combo_box_values(xpath_name) ⇒ Array<String>

Get all options for combobox or select

Parameters:

  • xpath_name (String)

    to find element

Returns:

  • (Array<String>)

    values



33
34
35
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/select_list_methods.rb', line 33

def get_all_combo_box_values(xpath_name)
  @driver.find_element(:xpath, xpath_name).find_elements(tag_name: 'option').map { |el| el.attribute('value') }
end

#get_element_index(text, list_elements) ⇒ Integer?

Get index of element by it’s text

Parameters:

  • text (String)

    to compare text

  • list_elements (Array<PageObject::Elements::Element>)

    array with PageObject elements to find in

Returns:

  • (Integer, nil)

    nil if nothing found, index if found



23
24
25
26
27
28
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/select_list_methods.rb', line 23

def get_element_index(text, list_elements)
  list_elements.each_with_index do |current, i|
    return i if get_text(current) == text
  end
  nil
end

#select_combo_box(xpath_name, select_value, select_by = :value) ⇒ void

This method returns an undefined value.

Select value of combo box

Parameters:

  • xpath_name (String)

    to find combobox

  • select_value (String)

    to select

  • select_by (Symbol) (defaults to: :value)

    select type, can be ‘:value` or `:text`



42
43
44
45
46
47
48
49
50
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/select_list_methods.rb', line 42

def select_combo_box(xpath_name, select_value, select_by = :value)
  wait_until_element_visible(xpath_name)
  option = Selenium::WebDriver::Support::Select.new(get_element(xpath_name))
  begin
    option.select_by(select_by, select_value)
  rescue StandardError
    option.select_by(:text, select_value)
  end
end

#select_from_list_elements(value, elements_value) ⇒ void

This method returns an undefined value.

Select from list elements

Parameters:

  • value (String)

    value to find object

  • elements_value (Array<PageObject::Elements::Element>)

    ‘elements` page object to select from

Raises:



11
12
13
14
15
16
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/select_list_methods.rb', line 11

def select_from_list_elements(value, elements_value)
  index = get_element_index(value, elements_value)
  webdriver_error(SelectEntryNotFound, "Select entry `#{value}` not found in #{elements_value}") if index.nil?

  elements_value[index].click
end