module SeleniumRecord::Actions
Contains simple actions to play from selenium objects
Public Class Methods
Chooses an option from select enhanced by javascript @param id [String] id of the select @param text [String] the option text
# 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
Public Instance Methods
Clicks accept button on popup
# File lib/selenium_record/actions.rb, line 10 def accept_popup popup = browser.switch_to.alert popup.accept end
Clear input of type ‘text’
# File lib/selenium_record/actions.rb, line 32 def clear(locator) el = find(locator) el.send_keys('') el.clear end
# File lib/selenium_record/actions.rb, line 51 def click(locator) cover { find(locator).click } end
@param text [String] text of the link to be clicked
# File lib/selenium_record/actions.rb, line 74 def click_link(text) finder = root_el || browser finder.find_element(link_text: text).click end
# File lib/selenium_record/actions.rb, line 38 def click_on(locator) find(locator).click end
Clicks on element and wait until all jquery events are dispatched @param how [Symbol] (:class, :class_name, :css, :id, :link_text, :link,
:partial_link_text, :name, :tag_name, :xpath)
@param what [String]
# File lib/selenium_record/actions.rb, line 46 def click_wait(locator) when_present(locator).click wait_js_inactive end
# File lib/selenium_record/actions.rb, line 55 def fill(locator, text) return unless text clear(locator) find(locator).send_keys(text || '') end
@param locator [Hash|Selenium::WebDriver::Element]
# 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
Drops the model view on the bottom to the top of the model type view list @param model_type [Symbol] the type of the views to be affected
# 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
@param id [Symbol] id of select element @param text [String] text of the option to be selected
# 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
# File lib/selenium_record/actions.rb, line 67 def submit click(xpath: ".//button[@type='submit']") wait_page_load load_dom end
# 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
Private Instance Methods
Chooses an option from select enhanced by javascript @param id [String] id of the select @param text [String] the option text
# 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