Module: OnlyofficeWebdriverWrapper::WebdriverAttributesHelper
- Included in:
- WebDriver
- Defined in:
- lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_attributes_helper.rb
Overview
Module with methods to work with attributes
Instance Method Summary collapse
- #attribute_exist?(xpath_name, attribute) ⇒ Boolean
- #get_attribute(xpath_name, attribute) ⇒ Object
- #get_attribute_from_displayed_element(xpath_name, attribute) ⇒ Object
- #get_attributes_of_several_elements(xpath_several_elements, attribute) ⇒ Object
- #get_element_by_parameter(elements, parameter_name, value) ⇒ Object
- #get_index_of_elements_with_attribute(xpath, attribute, value, only_visible = true) ⇒ Object
Instance Method Details
#attribute_exist?(xpath_name, attribute) ⇒ Boolean
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_attributes_helper.rb', line 4 def attribute_exist?(xpath_name, attribute) exist = false element = xpath_name.is_a?(String) ? get_element(xpath_name) : xpath_name begin attribute_value = element.attribute(attribute) exist = attribute_value.empty? || attribute_value.nil? ? false : true rescue Exception exist = false end exist end |
#get_attribute(xpath_name, attribute) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_attributes_helper.rb', line 17 def get_attribute(xpath_name, attribute) element = xpath_name.is_a?(Selenium::WebDriver::Element) ? xpath_name : get_element(xpath_name) if element.nil? webdriver_error("Webdriver.get_attribute(#{xpath_name}, #{attribute}) failed because element not found") else element.attribute(attribute) end end |
#get_attribute_from_displayed_element(xpath_name, attribute) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_attributes_helper.rb', line 31 def get_attribute_from_displayed_element(xpath_name, attribute) @driver.find_elements(:xpath, xpath_name).each do |current_element| return current_element.attribute(attribute) if current_element.displayed? end false end |
#get_attributes_of_several_elements(xpath_several_elements, attribute) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_attributes_helper.rb', line 38 def get_attributes_of_several_elements(xpath_several_elements, attribute) elements = @driver.find_elements(:xpath, xpath_several_elements) elements.map do |element| element.attribute(attribute) end end |
#get_element_by_parameter(elements, parameter_name, value) ⇒ Object
27 28 29 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_attributes_helper.rb', line 27 def get_element_by_parameter(elements, parameter_name, value) elements.find { |current_element| value == get_attribute(current_element, parameter_name) } end |
#get_index_of_elements_with_attribute(xpath, attribute, value, only_visible = true) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_attributes_helper.rb', line 46 def get_index_of_elements_with_attribute(xpath, attribute, value, only_visible = true) get_elements(xpath, only_visible).each_with_index do |element, index| return (index + 1) if get_attribute(element, attribute).include?(value) end 0 end |