Created
March 20, 2017 12:56
-
-
Save jsugarman/bc481d0f8b0164039f7a849b2ae932a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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