I'am trying to use jquery's selectors as custom Selenium locate strategy. Exactly as in this article http://johnjianfang.blogspot.com/2009/04/how-to-use-jquery-to-create-custom.html
Unfortunatly when I use selenium.click('jquery=a.mylink') method nothing happens.
But selenium.click('css=a.mylink') still works perfectly.
I did a little research and found that problem is in how jquery convers result of querySelectorAll. Here is the snippet from jquery 1.4.2:
Sizzle = function(query, context, extra, seed){
context = context || document;
// Only use querySelectorAll on non-XML documents
// (ID selectors don't work in non-HTML documents)
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 makeArray like this:
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;
};
It solves this strange problem.
Any ideas why this fix works??!