Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jsugarman/bc481d0f8b0164039f7a849b2ae932a7 to your computer and use it in GitHub Desktop.
Save jsugarman/bc481d0f8b0164039f7a849b2ae932a7 to your computer and use it in GitHub Desktop.
module Capybara
module Node
module Actions
alias_method :old_check, :check
alias_method :old_uncheck, :uncheck
def check locator
Capybara.current_session.evaluate_script js_element_check(locator, true)
end
def uncheck locator
Capybara.current_session.evaluate_script js_element_check(locator, false)
end
private
def js_find_by_id locator
element = <<-SCRIPT.strip.gsub(/\s+/,' ')
element = (function () {
var element = document.getElementById(\"#{locator}\");
return element;
})()
SCRIPT
end
def js_element_check locator, switch = true
checkbox = js_find_by_id(locator)
<<-SCRIPT
(function () {
#{checkbox}.checked = #{switch}
})()
SCRIPT
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment