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_index_of_elements_with_attribute(xpath, attribute, value, only_visible = true) ⇒ Object
Instance Method Details
#attribute_exist?(xpath_name, attribute) ⇒ Boolean
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_attributes_helper.rb', line 6 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
19 20 21 22 23 24 25 26 27 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_attributes_helper.rb', line 19 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
29 30 31 32 33 34 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_attributes_helper.rb', line 29 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
36 37 38 39 40 41 42 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_attributes_helper.rb', line 36 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_index_of_elements_with_attribute(xpath, attribute, value, only_visible = true) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_attributes_helper.rb', line 44 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 |