Skip to content

Instantly share code, notes, and snippets.

@dcrosby42
Created November 11, 2010 04:59
Show Gist options
  • Save dcrosby42/672032 to your computer and use it in GitHub Desktop.
Save dcrosby42/672032 to your computer and use it in GitHub Desktop.
Helper function to embed in your page to let WatiN execute a CSS-selector based search for a DOM element.
;WatinSearchHelper = function ($) {
var earTagId = 1;
var getElementId = function (cssSelector) {
var resultId = "_no_element_";
var el = $(cssSelector);
if (el.length > 0) {
var firstEl = el[0];
if (firstEl.id == "") {
// Give this element a contrived id so we can find it directly from the WatiN side:
firstEl.id = "_watin_search_" + earTagId++;
}
resultId = firstEl.id;
}
return resultId;
};
return { getElementId: getElementId };
} (jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment