Module: OnlyofficeWebdriverWrapper::WebdriverStyleHelper
- Included in:
- WebDriver
- Defined in:
- lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_style_helper.rb
Overview
Webdriver style helper
Instance Method Summary collapse
- #get_style_attributes_of_several_elements(xpath_several_elements, style) ⇒ Object
- #get_style_parameter(xpath, parameter_name) ⇒ Object
- #set_style_attribute(xpath, attribute, attribute_value) ⇒ Object
- #set_style_parameter(xpath, attribute, attribute_value) ⇒ Object
- #set_style_show_by_xpath(xpath, move_to_center = false) ⇒ Object
Instance Method Details
#get_style_attributes_of_several_elements(xpath_several_elements, style) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_style_helper.rb', line 12 def get_style_attributes_of_several_elements(xpath_several_elements, style) @driver.find_elements(:xpath, xpath_several_elements).map do |element| el_style = element.attribute('style') unless el_style.empty? found_style = el_style.split(';').find { |curr_param| curr_param.include?(style) } found_style&.gsub(/\s?#{style}:/, '') end end.compact end |
#get_style_parameter(xpath, parameter_name) ⇒ Object
6 7 8 9 10 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_style_helper.rb', line 6 def get_style_parameter(xpath, parameter_name) get_attribute(xpath, 'style').split(';').each do |current_param| return /:\s(.*);?$/.match(current_param)[1] if current_param.include?(parameter_name) end end |
#set_style_attribute(xpath, attribute, attribute_value) ⇒ Object
27 28 29 30 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_style_helper.rb', line 27 def set_style_attribute(xpath, attribute, attribute_value) execute_javascript("document.evaluate('#{xpath}',document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null)." \ "singleNodeValue.style.#{attribute}=\"#{attribute_value}\"") end |
#set_style_parameter(xpath, attribute, attribute_value) ⇒ Object
22 23 24 25 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_style_helper.rb', line 22 def set_style_parameter(xpath, attribute, attribute_value) execute_javascript("document.evaluate(\"#{xpath.tr('"', "'")}\",document, null, XPathResult.ANY_TYPE, null ).iterateNext()." \ "style.#{attribute}=\"#{attribute_value}\"") end |
#set_style_show_by_xpath(xpath, move_to_center = false) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_style_helper.rb', line 32 def set_style_show_by_xpath(xpath, move_to_center = false) xpath.tr!("'", '"') execute_javascript('document.evaluate( \'' + xpath.to_s + '\' ,document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue.style.display = "block";') return unless move_to_center execute_javascript('document.evaluate( \'' + xpath.to_s + '\' ,document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue.style.left = "410px";') execute_javascript('document.evaluate( \'' + xpath.to_s + '\' ,document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue.style.top = "260px";') end |