Module: SeleniumRecord::Actions
- Included in:
- Base, Scopes::LocatorScope
- Defined in:
- lib/selenium_record/actions.rb
Overview
Contains simple actions to play from selenium objects
Class Method Summary collapse
-
.choose_option(id, text) ⇒ Object
Chooses an option from select enhanced by javascript.
Instance Method Summary collapse
-
#accept_popup ⇒ Object
Clicks accept button on popup.
-
#choose_menu(dropdown, menu) ⇒ Object
Chooses a menu from dropdown enhanced by javascript.
-
#clear(locator) ⇒ Object
Clear input of type ‘text’.
- #click(locator) ⇒ Object
- #click_link(text) ⇒ Object
- #click_on(locator) ⇒ Object
-
#click_wait(locator) ⇒ Object
Clicks on element and wait until all jquery events are dispatched.
- #fill(locator, text) ⇒ Object
- #focus(locator) ⇒ Object
-
#pop_last(model_type) ⇒ Object
Drops the model view on the bottom to the top of the model type view list.
- #select_from_chosen(id, text) ⇒ Object
- #submit ⇒ Object
- #textarea_content(locator, content) ⇒ Object
Class Method Details
.choose_option(id, text) ⇒ Object
Chooses an option from select enhanced by javascript
18 19 20 21 |
# File 'lib/selenium_record/actions.rb', line 18 def choose_option(id, text) click_wait xpath: select_xpath(id) click_wait xpath: select_option_xpath(id, text) end |
Instance Method Details
#accept_popup ⇒ Object
Clicks accept button on popup
10 11 12 13 |
# File 'lib/selenium_record/actions.rb', line 10 def accept_popup popup = browser.switch_to.alert popup.accept end |
#choose_menu(dropdown, menu) ⇒ Object
Chooses a menu from dropdown enhanced by javascript
26 27 28 29 |
# File 'lib/selenium_record/actions.rb', line 26 def (dropdown, ) click_wait xpath: dropdown_xpath(trans dropdown) click_wait xpath: (trans ) end |
#clear(locator) ⇒ Object
Clear input of type ‘text’
32 33 34 35 36 |
# File 'lib/selenium_record/actions.rb', line 32 def clear(locator) el = find(locator) el.send_keys('') el.clear end |
#click(locator) ⇒ Object
51 52 53 |
# File 'lib/selenium_record/actions.rb', line 51 def click(locator) cover { find(locator).click } end |
#click_link(text) ⇒ Object
74 75 76 77 |
# File 'lib/selenium_record/actions.rb', line 74 def click_link(text) finder = root_el || browser finder.find_element(link_text: text).click end |
#click_on(locator) ⇒ Object
38 39 40 |
# File 'lib/selenium_record/actions.rb', line 38 def click_on(locator) find(locator).click end |
#click_wait(locator) ⇒ Object
Clicks on element and wait until all jquery events are dispatched
46 47 48 49 |
# File 'lib/selenium_record/actions.rb', line 46 def click_wait(locator) when_present(locator).click wait_js_inactive end |
#fill(locator, text) ⇒ Object
55 56 57 58 59 |
# File 'lib/selenium_record/actions.rb', line 55 def fill(locator, text) return unless text clear(locator) find(locator).send_keys(text || '') end |
#focus(locator) ⇒ Object
62 63 64 65 |
# File 'lib/selenium_record/actions.rb', line 62 def focus(locator) element = (locator.is_a?(Hash) && find(locator)) || locator browser.action.move_to(element).perform end |
#pop_last(model_type) ⇒ Object
Drops the model view on the bottom to the top of the model type view list
81 82 83 84 85 |
# File 'lib/selenium_record/actions.rb', line 81 def pop_last(model_type) elements = send("#{model_type}_elements") browser.action .drag_and_drop(elements.last, elements.first).perform end |
#select_from_chosen(id, text) ⇒ Object
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/selenium_record/actions.rb', line 89 def select_from_chosen(id, text) browser.execute_script <<-script var optValue = $("##{id} option:contains('#{text}')").val(); var value = [optValue]; if ($('##{id}').val()) { $.merge(value, $('##{id}').val()); } $('##{id}').val(value).trigger('chosen:updated'); script end |
#submit ⇒ Object
67 68 69 70 71 |
# File 'lib/selenium_record/actions.rb', line 67 def submit click(xpath: ".//button[@type='submit']") wait_page_load load_dom end |
#textarea_content(locator, content) ⇒ Object
4 5 6 7 |
# File 'lib/selenium_record/actions.rb', line 4 def textarea_content(locator, content) find(locator).clear # gain focus on textarea find(locator).send_keys content end |