Skip to content

Instantly share code, notes, and snippets.

@mattheworiordan
Created August 23, 2011 22:47
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 mattheworiordan/1166821 to your computer and use it in GitHub Desktop.
Save mattheworiordan/1166821 to your computer and use it in GitHub Desktop.
Fix for :focus pseudo selector when browser does not have focus
/**
* JQuery tries to use native CSS selectors instead of the Sizzle selector
* engine for performance reasons.
*
* This causes problems when trying to test intefaces using the
* :focus pseudo selector as unless the web page and browser window
* has the focus, all elements are considered to be without focus.
* Checking for :focus in Selenium or Capybara tests therefore fail if
* using JQuery or Sizzle.
*
* Sizzle will however return true for a :focus element even if the
* window itself has lost focus if we force it not use the native selector functions
* This script forces Sizzle to use its own engine over native selectors.
*
* This file MUST be included before JQuery or Sizzle is loaded
*
* Refer to http://blog.mattheworiordan.com/post/9308775285 for more info
*
**/
/* Prevent use of native find selector */
document.querySelectorAll = false;
/* Prevent use of native matches selector */
document.documentElement.matchesSelector = false;
document.documentElement.mozMatchesSelector = false;
document.documentElement.webkitMatchesSelector = false;
document.documentElement.msMatchesSelector = false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment