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) ⇒ Object
- #key_up(xpath, key) ⇒ Object
- #press_key(key) ⇒ Object
- #send_keys(xpath_name, text_to_send, by_action = true) ⇒ Object
- #send_keys_to_focused_elements(keys, count_of_times = 1) ⇒ Object
- #type_text(element, text_to_send, clear_area = false) ⇒ Object
- #type_text_and_select_it(element, text_to_send, clear_area = false) ⇒ Object
- #type_to_input(xpath_name, text_to_send, clear_content = false, click_on_it = true) ⇒ Object
- #type_to_locator(xpath_name, text_to_send, clear_content = true, click_on_it = false, by_action = false, by_element_send_key = false) ⇒ Object
Instance Method Details
#key_down(xpath, key) ⇒ Object
81 82 83 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb', line 81 def key_down(xpath, key) @driver.action.key_down(get_element(xpath), key).perform end |
#key_up(xpath, key) ⇒ Object
85 86 87 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb', line 85 def key_up(xpath, key) @driver.action.key_up(get_element(xpath), key).perform end |
#press_key(key) ⇒ Object
77 78 79 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb', line 77 def press_key(key) @driver.action.send_keys(key).perform end |
#send_keys(xpath_name, text_to_send, by_action = true) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb', line 61 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) ⇒ Object
71 72 73 74 75 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb', line 71 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) ⇒ Object
6 7 8 9 10 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb', line 6 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) ⇒ Object
12 13 14 15 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb', line 12 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) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb', line 45 def type_to_input(xpath_name, text_to_send, clear_content = false, click_on_it = true) element = get_element(xpath_name) webdriver_error(Selenium::WebDriver::Error::NoSuchElementError, "type_to_input(#{xpath_name}, #{text_to_send}, #{clear_content}, #{click_on_it}): element not found") if element.nil? element.clear if clear_content sleep 0.2 if click_on_it begin element.click rescue Exception => e webdriver_error("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) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb', line 17 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 Exception => e webdriver_error("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 if click_on_it click_on_locator(xpath_name) sleep 0.2 end if (@browser != :chrome && !by_action) || by_element_send_key element.send_keys text_to_send elsif text_to_send != '' if text_to_send.is_a?(String) text_to_send.split(//).each do |symbol| @driver.action.send_keys(symbol).perform end else @driver.action.send_keys(text_to_send).perform end end end |