lundi 7 septembre 2020

How can I detect/identify/find an element on web page

I would like to detect the element test_id which is hidden in a fragment, see the last line <script type="text/javascript">!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod? n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n; n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0; t.src=v;s=b const $ws_params ={"test_id":0, "uni_mode":0};</script>

The code I`ve got in tampermonkey is:

(function() {
    var training = document.getElementsByName("test_id")
    if (training[0]) {
      alert("This page is tested");
    }   
})();

Or another:

window.addEventListener('DOMContentLoaded', (event) => {
    console.log('DOM fully loaded and parsed');
});
function contains(selector, text) {
  var elements = document.querySelectorAll(selector);
  return Array.prototype.filter.call(elements, function(element){
    return RegExp(text).test(element.textContent);
  });
}
contains('script', 'test_id'); 

What do I need to change, to make it run?

Currently, I`m using AHK code, every time I am running it when I go to a new page that goes through the procedure:

  1. press Ctrl+Shift+I
  2. press Ctrl+F
  3. type test_id And if it has been found I can see it, otherwise no that element.



Aucun commentaire:

Enregistrer un commentaire