All Downloads are FREE. Search and download functionalities are using the official Maven repository.

enium.healenium-web.3.5.4.source-code.itemsWithAttributesXpath.js Maven / Gradle / Ivy

The newest version!

var xpathElement = document.evaluate(arguments[0], document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null,).singleNodeValue;
var items = [];
var result = {items: null, url: null};
var a = xpathElement;
while (a != document) {
  var child = a;
  var i=0; while(child=child.previousElementSibling) i++;
  var node = {tag:null,id:null,index:null,classes:[],other:{},innerText:""};
  if (a.tagName !== undefined) {
    node.tag = a.tagName.toLowerCase();
  }
  node.id = a.id;
  node.index = i;
  node.innerText = a.innerText;

  if (a.hasAttribute("class")) {
	  node.classes = a.attributes.class.value.split(' ');
  }
  for (index = 0; index < a.attributes.length; ++index) {
      var attrName = a.attributes[index].name;
      if (["id","class"].indexOf(attrName) == -1){
		    node.other[attrName] = a.attributes[index].value;
      }
  };

  items.unshift(node);
  a = a.parentNode;
}
result.items = items;
result.url = window.location.href;
return {json: JSON.stringify(result), element: xpathElement};




© 2015 - 2024 Weber Informatics LLC | Privacy Policy