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
Check if attribute of xpath is exists.
-
#get_attribute(xpath_name, attribute) ⇒ String
Get attribute of element.
-
#get_attributes_of_several_elements(xpath_several_elements, attribute) ⇒ Array<String>
Get attributes of several elements.
-
#get_index_of_elements_with_attribute(xpath, attribute, value, only_visible = true) ⇒ Integer
Get index of element from array with attribute value.
-
#remove_attribute(xpath, attribute) ⇒ String
Remove attribute of element.
-
#set_attribute(xpath, attribute, attribute_value) ⇒ String
(also: #set_parameter)
Set element attribute.
Instance Method Details
#attribute_exist?(xpath_name, attribute) ⇒ Boolean
Check if attribute of xpath is exists
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_attributes_helper.rb', line 10 def attribute_exist?(xpath_name, attribute) 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?) rescue StandardError exist = false end exist end |
#get_attribute(xpath_name, attribute) ⇒ String
Get attribute of element
25 26 27 28 29 30 31 32 33 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_attributes_helper.rb', line 25 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_attributes_of_several_elements(xpath_several_elements, attribute) ⇒ Array<String>
Get attributes of several elements
39 40 41 42 43 44 45 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_attributes_helper.rb', line 39 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) ⇒ Integer
Get index of element from array with attribute value
53 54 55 56 57 58 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_attributes_helper.rb', line 53 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 |
#remove_attribute(xpath, attribute) ⇒ String
Remove attribute of element
75 76 77 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_attributes_helper.rb', line 75 def remove_attribute(xpath, attribute) execute_javascript("#{dom_element_by_xpath(xpath)}.removeAttribute('#{attribute}');") end |
#set_attribute(xpath, attribute, attribute_value) ⇒ String Also known as: set_parameter
Set element attribute
65 66 67 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_attributes_helper.rb', line 65 def set_attribute(xpath, attribute, attribute_value) execute_javascript("#{dom_element_by_xpath(xpath)}.#{attribute}=\"#{attribute_value}\";") end |