Module: OnlyofficeWebdriverWrapper::WebdriverTypeHelper
- Included in:
- WebDriver
- Defined in:
- lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb
Overview
Class for helping with type stuff
Instance Method Summary collapse
-
#key_down(xpath, key) ⇒ void
Simulate pressed down key on object.
-
#key_up(xpath, key) ⇒ void
Release pressed key from object.
-
#press_key(key) ⇒ void
Press some specific key.
-
#send_keys(xpath_name, text_to_send, by_action = true) ⇒ void
Send keys to object.
-
#send_keys_to_focused_elements(keys, count_of_times = 1) ⇒ void
Type text to currently focused element.
-
#type_text(element, text_to_send, clear_area = false) ⇒ void
Type text to element.
-
#type_text_and_select_it(element, text_to_send, clear_area = false) ⇒ void
Type text to element and select it.
-
#type_to_input(xpath_name, text_to_send, clear_content = false, click_on_it = true) ⇒ void
Type text to input.
-
#type_to_locator(xpath_name, text_to_send, clear_content = true, click_on_it = false, by_action = false, by_element_send_key = false) ⇒ void
Type text to object.
Instance Method Details
#key_down(xpath, key) ⇒ void
This method returns an undefined value.
Simulate pressed down key on object
130 131 132 133 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb', line 130 def key_down(xpath, key) @driver.action.key_down(get_element(xpath), key).perform sleep(1) # for some reason quick key_down select text in control end |
#key_up(xpath, key) ⇒ void
This method returns an undefined value.
Release pressed key from object
139 140 141 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb', line 139 def key_up(xpath, key) @driver.action.key_up(get_element(xpath), key).perform end |
#press_key(key) ⇒ void
This method returns an undefined value.
Press some specific key
122 123 124 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb', line 122 def press_key(key) @driver.action.send_keys(key).perform end |
#send_keys(xpath_name, text_to_send, by_action = true) ⇒ void
This method returns an undefined value.
Send keys to object
99 100 101 102 103 104 105 106 107 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb', line 99 def send_keys(xpath_name, text_to_send, by_action = true) element = get_element(xpath_name) @driver.action.click(element).perform if @browser == :firefox if by_action @driver.action.send_keys(element, text_to_send).perform else element.send_keys text_to_send end end |
#send_keys_to_focused_elements(keys, count_of_times = 1) ⇒ void
This method returns an undefined value.
Type text to currently focused element
113 114 115 116 117 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb', line 113 def send_keys_to_focused_elements(keys, count_of_times = 1) command = @driver.action.send_keys(keys) (count_of_times - 1).times { command = command.send_keys(keys) } command.perform end |
#type_text(element, text_to_send, clear_area = false) ⇒ void
This method returns an undefined value.
Type text to element
11 12 13 14 15 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb', line 11 def type_text(element, text_to_send, clear_area = false) element = get_element(element) element.clear if clear_area element.send_keys(text_to_send) end |
#type_text_and_select_it(element, text_to_send, clear_area = false) ⇒ void
This method returns an undefined value.
Type text to element and select it
22 23 24 25 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb', line 22 def type_text_and_select_it(element, text_to_send, clear_area = false) type_text(element, text_to_send, clear_area) text_to_send.length.times { element.send_keys %i[shift left] } end |
#type_to_input(xpath_name, text_to_send, clear_content = false, click_on_it = true) ⇒ void
This method returns an undefined value.
Type text to input
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb', line 71 def type_to_input(xpath_name, text_to_send, clear_content = false, click_on_it = true) element = get_element(xpath_name) if element.nil? webdriver_error(Selenium::WebDriver::Error::NoSuchElementError, "type_to_input(#{xpath_name}, #{text_to_send}, " \ "#{clear_content}, #{click_on_it}): element not found") end element.clear if clear_content sleep 0.2 if click_on_it begin element.click rescue StandardError => e webdriver_error(e.class, "type_to_input(#{xpath_name}, #{text_to_send}, " \ "#{clear_content}, #{click_on_it}) " \ "error in 'element.click' error: #{e}") end sleep 0.2 end element.send_keys text_to_send end |
#type_to_locator(xpath_name, text_to_send, clear_content = true, click_on_it = false, by_action = false, by_element_send_key = false) ⇒ void
This method returns an undefined value.
Type text to object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb', line 35 def type_to_locator(xpath_name, text_to_send, clear_content = true, click_on_it = false, by_action = false, by_element_send_key = false) element = get_element(xpath_name) if clear_content begin element.clear rescue StandardError => e webdriver_error(e.class, "Error in element.clear #{e} for " \ "type_to_locator(#{xpath_name}, #{text_to_send}, " \ "#{clear_content}, #{click_on_it}, " \ "#{by_action}, #{by_element_send_key})") end end click_on_locator(xpath_name, after_timeout: 0.2) if click_on_it if (@browser != :chrome && !by_action) || by_element_send_key element.send_keys text_to_send else send_text_by_chars(text_to_send) end rescue Selenium::WebDriver::Error::JavascriptError webdriver_error(Selenium::WebDriver::Error::InvalidElementStateError, "Invalid state of element: #{xpath_name}") end |