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
-
#get_all_combo_box_values(xpath_name) ⇒ Array<String>
Get all options for combobox or select.
-
#get_element_index(text, list_elements) ⇒ Integer?
Get index of element by it’s text.
-
#select_combo_box(xpath_name, select_value, select_by = :value) ⇒ void
Select value of combo box.
-
#select_from_list_elements(value, elements_value) ⇒ void
Select from list elements.
Instance Method Details
#get_all_combo_box_values(xpath_name) ⇒ Array<String>
Get all options for combobox or select
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
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
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
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 |