Skip to content

Instantly share code, notes, and snippets.

@halogenandtoast
Created June 8, 2018 13:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halogenandtoast/163aab6497dd7db1dd396df967058ce3 to your computer and use it in GitHub Desktop.
Save halogenandtoast/163aab6497dd7db1dd396df967058ce3 to your computer and use it in GitHub Desktop.
Paste helper for capybara and chromedriver (may work with other drivers)
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