Module: OnlyofficeWebdriverWrapper::ClickMethods
- Included in:
- WebDriver
- Defined in:
- lib/onlyoffice_webdriver_wrapper/webdriver/click_methods.rb,
lib/onlyoffice_webdriver_wrapper/webdriver/element_getters.rb
Overview
Methods to get elements
Instance Method Summary collapse
-
#click(element) ⇒ nil
Click on specified element.
-
#click_on_displayed(xpath_name) ⇒ nil
Click on one of several which displayed.
-
#click_on_locator(xpath_name, by_javascript = false, count: 1, after_timeout: 0) ⇒ Object
Click on locator.
-
#click_on_locator_coordinates(xpath_name, right_by, down_by) ⇒ nil
Click on locator by coordinates.
-
#click_on_one_of_several_by_display(xpath_several_elements) ⇒ True, False
Click on one of several which displayed.
-
#click_on_one_of_several_by_parameter(xpath_several_elements, parameter_name, parameter_value) ⇒ True, False
Click on one of several xpath filtered by parameter and value.
-
#double_click(xpath_name) ⇒ nil
Perform double_click on element.
-
#double_click_on_locator_coordinates(xpath_name, right_by, down_by) ⇒ nil
Perform double_click on specified coordinates.
-
#get_element(object_identification) ⇒ Object?
Get element by it’s xpath.
-
#get_element_by_display(xpath_name) ⇒ Object
Get first visible element from several.
-
#get_elements(objects_identification, only_visible = true) ⇒ Array, Object
Get array of webdriver object by xpath.
-
#right_click(xpath_name) ⇒ nil
Perform right click on xpath.
-
#right_click_on_locator_coordinates(xpath_name, right_by = nil, down_by = nil) ⇒ nil
Perform right click on locator with specified coordinates.
Instance Method Details
#click(element) ⇒ nil
Click on specified element
9 10 11 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/click_methods.rb', line 9 def click(element) element.click end |
#click_on_displayed(xpath_name) ⇒ nil
Click on one of several which displayed
45 46 47 48 49 50 51 52 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/click_methods.rb', line 45 def click_on_displayed(xpath_name) element = get_element_by_display(xpath_name) begin element.is_a?(Array) ? element.first.click : element.click rescue StandardError => e webdriver_error(e.class, "Exception #{e} in click_on_displayed(#{xpath_name})") end end |
#click_on_locator(xpath_name, by_javascript = false, count: 1, after_timeout: 0) ⇒ Object
Click on locator
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/click_methods.rb', line 18 def click_on_locator(xpath_name, by_javascript = false, count: 1, after_timeout: 0) element = get_element(xpath_name) return webdriver_error("Element with xpath: #{xpath_name} not found") if element.nil? click_function = if by_javascript -> { execute_javascript("#{dom_element_by_xpath(xpath_name)}.click();") } else -> { element.click } end begin count.times do click_function.call sleep(after_timeout) end rescue Selenium::WebDriver::Error::ElementNotInteractableError => e webdriver_error(e.class, 'Selenium::WebDriver::Error::ElementNotInteractableError: ' \ "element not visible for xpath: #{xpath_name}") rescue StandardError => e webdriver_error(e.class, "UnknownError #{e.} #{xpath_name}") end end |
#click_on_locator_coordinates(xpath_name, right_by, down_by) ⇒ nil
Click on locator by coordinates
59 60 61 62 63 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/click_methods.rb', line 59 def click_on_locator_coordinates(xpath_name, right_by, down_by) wait_until_element_visible(xpath_name) move_to_driver_action(xpath_name, right_by, down_by).perform move_to_driver_action(xpath_name, right_by, down_by).click.perform end |
#click_on_one_of_several_by_display(xpath_several_elements) ⇒ True, False
Click on one of several which displayed
68 69 70 71 72 73 74 75 76 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/click_methods.rb', line 68 def click_on_one_of_several_by_display(xpath_several_elements) @driver.find_elements(:xpath, xpath_several_elements).each do |current_element| if current_element.displayed? current_element.click return true end end false end |
#click_on_one_of_several_by_parameter(xpath_several_elements, parameter_name, parameter_value) ⇒ True, False
Click on one of several xpath filtered by parameter and value
83 84 85 86 87 88 89 90 91 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/click_methods.rb', line 83 def click_on_one_of_several_by_parameter(xpath_several_elements, parameter_name, parameter_value) @driver.find_elements(:xpath, xpath_several_elements).each do |current_element| if current_element.attribute(parameter_name).include? parameter_value current_element.click return true end end false end |
#double_click(xpath_name) ⇒ nil
Perform double_click on element
116 117 118 119 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/click_methods.rb', line 116 def double_click(xpath_name) wait_until_element_visible(xpath_name) @driver.action.move_to(@driver.find_element(:xpath, xpath_name)).double_click.perform end |
#double_click_on_locator_coordinates(xpath_name, right_by, down_by) ⇒ nil
Perform double_click on specified coordinates
126 127 128 129 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/click_methods.rb', line 126 def double_click_on_locator_coordinates(xpath_name, right_by, down_by) wait_until_element_visible(xpath_name) move_to_driver_action(xpath_name, right_by, down_by).double_click.perform end |
#get_element(object_identification) ⇒ Object?
Get element by it’s xpath
9 10 11 12 13 14 15 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/element_getters.rb', line 9 def get_element(object_identification) return object_identification unless object_identification.is_a?(String) @driver.find_element(:xpath, object_identification) rescue StandardError nil end |
#get_element_by_display(xpath_name) ⇒ Object
Get first visible element from several
21 22 23 24 25 26 27 28 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/element_getters.rb', line 21 def get_element_by_display(xpath_name) @driver.find_elements(:xpath, xpath_name).each do |element| return element if element.displayed? end rescue Selenium::WebDriver::Error::InvalidSelectorError, Selenium::WebDriver::Error::JavascriptError webdriver_error(Selenium::WebDriver::Error::InvalidSelectorError, "Invalid Selector: get_element_by_display('#{xpath_name}')") end |
#get_elements(objects_identification, only_visible = true) ⇒ Array, Object
Get array of webdriver object by xpath
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/element_getters.rb', line 34 def get_elements(objects_identification, only_visible = true) return objects_identification if objects_identification.is_a?(Array) elements = @driver.find_elements(:xpath, objects_identification) if only_visible elements.each do |current| elements.delete(current) unless @browser == :firefox || current.displayed? end end elements end |
#right_click(xpath_name) ⇒ nil
Perform right click on xpath
96 97 98 99 100 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/click_methods.rb', line 96 def right_click(xpath_name) wait_until_element_visible(xpath_name) @driver.action.context_click(@driver.find_element(:xpath, xpath_name)).perform end |
#right_click_on_locator_coordinates(xpath_name, right_by = nil, down_by = nil) ⇒ nil
Perform right click on locator with specified coordinates
107 108 109 110 111 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/click_methods.rb', line 107 def right_click_on_locator_coordinates(xpath_name, right_by = nil, down_by = nil) wait_until_element_visible(xpath_name) move_to_driver_action(xpath_name, right_by, down_by).perform move_to_driver_action(xpath_name, right_by, down_by).context_click.perform end |