Created
June 8, 2018 13:44
-
-
Save halogenandtoast/163aab6497dd7db1dd396df967058ce3 to your computer and use it in GitHub Desktop.
Paste helper for capybara and chromedriver (may work with other drivers)
This file contains hidden or 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
def paste_in(field_label, with:) | |
field = find_field(field_label) | |
selector = "##{field["id"]}" | |
script = <<-JS | |
dt = new DataTransfer(); | |
dt.setData("text/plain", '#{with}'); | |
ev = new ClipboardEvent("paste", { clipboardData: dt }); | |
$('#{selector}')[0].dispatchEvent(ev) | |
JS | |
page.execute_script(script) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment