Skip to content

Instantly share code, notes, and snippets.

@jarib
Created August 18, 2011 11:37
Show Gist options
  • Save jarib/1153898 to your computer and use it in GitHub Desktop.
Save jarib/1153898 to your computer and use it in GitHub Desktop.
focus/blur in single display
require 'selenium-webdriver'
browser1 = Selenium::WebDriver.for :firefox
browser2 = Selenium::WebDriver.for :firefox # steals focus
begin
url = "data:text/html;content-type=utf-8,#{URI.escape DATA.read}"
browser1.get url
browser2.get url
browser1.find_element(:id => "field").send_keys "hello"
browser1.find_element(:id => "log").click
p :browser1 => browser1.find_element(:id => "log").text
browser2.find_element(:id => "field").send_keys "hello"
browser2.find_element(:id => "log").click
p :browser2 => browser2.find_element(:id => "log").text
ensure
browser1.quit
browser2.quit
end
__END__
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Page Title</title>
</head>
<script>
function log(msg) {
document.getElementById("log").innerHTML += "<p>" + msg + "</p>";
};
</script>
<body>
<input id=field type="text" onfocus="log('focus')" onblur="log('blur')">
<div id=log></div>
</body>
</html>
finn@qa1:/tmp$ DISPLAY=:2 ruby -rubygems focus_test.rb
{:browser1=>"focus\nblur"}
{:browser2=>"focus\nblur"}
finn@qa1:/tmp$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment