WWW-Selenium-Utils
view release on metacpan or search on metacpan
website/selenium/html-xpath/html-xpath-patched.js view on Meta::CPAN
}
function onPropertyChangeEventHandler()
{
document._propertyChangeDetected = true;
}
this.documentChangeDetected = function()
{
return (document.ignoreDocumentChanges ? false : this._currentElementCount != document.all.length || document._propertyChangeDetected);
}
function activateDom(helper)
{
if (!helper.dom)
{
var dom = new ActiveXObject("Msxml2.DOMDocument");
/** SELENIUM:PATCH TO ALLOW PROVIDE FULL XPATH SUPPORT */
dom.setProperty("SelectionLanguage", "XPath");
/** END SELENIUM:PATCH */
dom.async = false;
dom.resolveExternals = false;
loadDocument(dom, helper);
helper.dom = dom;
helper._currentElementCount = document.all.length;
document._propertyChangeDetected = false;
}
else
{
if (helper.documentChangeDetected())
{
var dom = helper.dom;
dom.load("");
loadDocument(dom, helper);
helper._currentElementCount = document.all.length;
document._propertyChangeDetected = false;
}
}
}
function loadDocument(dom, helper)
{
return loadNode(dom, dom, document.body, helper);
}
/** SELENIUM:PATCH for loadNode() - see SEL-68 */
function loadNode(dom, domParentNode, node, helper)
{
// Bad node scenarios
// 1. If the node contains a /, it's broken HTML
// 2. If the node doesn't have a name (typically from broken HTML), the node can't be loaded
// 3. Node types we can't deal with
//
// In all scenarios, we just skip the node. We won't be able to
// query on these nodes, but they're broken anyway.
if (node.nodeName.indexOf("/") > -1
|| node.nodeName == ""
|| node.nodeName == "#document"
|| node.nodeName == "#document-fragment"
|| node.nodeName == "#cdata-section"
|| node.nodeName == "#xml-declaration"
|| node.nodeName == "#whitespace"
|| node.nodeName == "#significat-whitespace"
)
{
return;
}
// #comment is a <!-- comment -->, which must be created with createComment()
if (node.nodeName == "#comment")
{
try
{
domParentNode.appendChild(dom.createComment(node.nodeValue));
}
catch (ex)
{
// it's just a comment, we don't care
}
}
else if (node.nodeType == 3)
{
domParentNode.appendChild(dom.createTextNode(node.nodeValue));
}
else
{
var domNode = dom.createElement(node.nodeName.toLowerCase());
if (!node.id)
{
node.id = node.uniqueID;
}
domParentNode.appendChild(domNode);
loadAttributes(dom, domNode, node);
var length = node.childNodes.length;
for(var i = 0; i < length; i ++ )
{
loadNode(dom, domNode, node.childNodes[i], helper);
}
node.attachEvent("onpropertychange", onPropertyChangeEventHandler);
}
}
/** END SELENIUM:PATCH */
function loadAttributes(dom, domParentNode, node)
{
for (var i = 0; i < node.attributes.length; i ++ )
{
var attribute = node.attributes[i];
var attributeValue = attribute.nodeValue;
if (attributeValue && attribute.specified)
{
var domAttribute = dom.createAttribute(attribute.nodeName);
domAttribute.value = attributeValue;
domParentNode.setAttributeNode(domAttribute);
}
}
}
}
}
( run in 1.158 second using v1.01-cache-2.11-cpan-63c85eba8c4 )