Sunday, September 8, 2013

Find elements by XPath with JavaScript (example)


Get elements from action menu on mail page of yandex.ru:

r = document.evaluate("//*[@class='b-toolbar__block b-toolbar__block_chevron']/a", document, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);

el = r.iterateNext();

while(el) { 
  if (window.getComputedStyle(el).display == "none") {
    continue; 
  } 
  console.log(el.getAttribute('data-action')); 
  el=r.iterateNext();
}





No comments:

Post a Comment