I am trying to use the jQuery Sizzle selection mechanism as a custom Selenium localization API, as in this article: http://johnjianfang.blogspot.com/2009/04/how-to-use-jquery-to-create-custom.html p>
Unfortunately, when I use selenium.click('jquery=a.mylink'), nothing happens.
selenium.click('css=a.mylink') works great.
I did a little research and found that the problem is how jQuery translates the result of the API querySelectorAll. Here is a snippet from jQuery 1.4.2:
Sizzle = function(query, context, extra, seed){
context = context || document;
if ( !seed && context.nodeType === 9 && !isXML(context) ) {
try {
return makeArray( context.querySelectorAll(query), extra );
} catch(e){}
}
return oldSizzle(query, context, extra, seed);
};
var makeArray = function(array, results) {
array = Array.prototype.slice.call( array, 0 );
if ( results ) {
results.push.apply( results, array );
return results;
}
return array;
};
When I change makeArrayas follows:
var makeArray = function(arrayLikeObject, results) {
var array = new Array(arrayLikeObject.length);
for (var i = 0, n = arrayLikeObject.length; i < n; i++) {
array[i] = arrayLikeObject[i];
}
if ( results ) {
results.push.apply( results, array );
return results;
}
return array;
};
Solves this strange problem.
Any ideas why this fix works ?!