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_text_by_symbol(xpath_name, text_to_send, clear_content = true, click_on_it = false, by_action = false, by_element_send_key = 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
96 97 98 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb', line 96 def key_down(xpath, key) @driver.action.key_down(get_element(xpath), key).perform end |
#key_up(xpath, key) ⇒ Object
100 101 102 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb', line 100 def key_up(xpath, key) @driver.action.key_up(get_element(xpath), key).perform end |
#press_key(key) ⇒ Object
92 93 94 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb', line 92 def press_key(key) @driver.action.send_keys(key).perform end |
#send_keys(xpath_name, text_to_send, by_action = true) ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb', line 76 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
86 87 88 89 90 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb', line 86 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
4 5 6 7 8 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb', line 4 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
10 11 12 13 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb', line 10 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_text_by_symbol(xpath_name, text_to_send, clear_content = true, click_on_it = false, by_action = false, by_element_send_key = false) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb', line 59 def type_text_by_symbol(xpath_name, text_to_send, clear_content = true, click_on_it = false, by_action = false, by_element_send_key = false) click_on_locator(xpath_name) if click_on_it element = get_element(xpath_name) if clear_content element.clear click_on_locator(xpath_name) if click_on_it end text_to_send.scan(/./).each do |symbol| sleep(0.3) if (@browser != :chrome && !by_action) || by_element_send_key send_keys(element, symbol, :element_send_key) else send_keys(element, symbol, by_action) end end end |
#type_to_input(xpath_name, text_to_send, clear_content = false, click_on_it = true) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb', line 43 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
15 16 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 |
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_type_helper.rb', line 15 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 |