Skip to content

Instantly share code, notes, and snippets.

@ivaravko
Forked from jarib/test.rb
Created August 23, 2011 14:30
Show Gist options
  • Save ivaravko/1165278 to your computer and use it in GitHub Desktop.
Save ivaravko/1165278 to your computer and use it in GitHub Desktop.
require 'selenium-webdriver'
ctrl = Selenium::WebDriver::Platform.os == :macosx ? :command : :control
browser = Selenium::WebDriver.for :chrome
begin
browser.get "data:text/html;content-type=utf-8,#{URI.escape DATA.read}"
receiver = browser.find_element(:id => "receiver")
receiver.send_keys 'foo'
receiver.send_keys [ctrl, 'a'], :backspace
p receiver.attribute(:value) # should be empty
ensure
browser.quit
end
__END__
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Keylogger</title>
<script type="text/javascript" charset="utf-8">
function log (e) {
document.getElementById('output').innerHTML += "<p>" + e.toString() + "</p>";
}
</script>
</head>
<body>
<input type="text" id="receiver" onkeydown="log(this)">
<div id="output"></div>
</body>
</html>
# output with firefox:
""
# output with chrome:
"fo"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment