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
10 11 12 13 14 15 16 17 18 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_style_helper.rb', line 10 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 }:/, '') unless found_style.nil? end end.compact end |
#get_style_parameter(xpath, parameter_name) ⇒ Object
4 5 6 7 8 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_style_helper.rb', line 4 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
25 26 27 28 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_style_helper.rb', line 25 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
20 21 22 23 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_style_helper.rb', line 20 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
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_style_helper.rb', line 30 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 |