Currently, I am facing a challenge in automatically retrieving elements from a webpage and I seem to be stuck on a few things.
My approach involves looping through all classes named 'trList' using document.getElementsByClassName('trList') to gather the necessary information.
Once I have gathered multiple results, I am attempting to extract parameters from elements like this:
<div id="action_0" onclick= ... >…</div>
Specifically, I am trying to retrieve the 1st and 9th parameters from the onclick function. Given that there are several iterations of this function among the results obtained through GetelementsByClassName, I am unsure about how to proceed.
Any guidance on how to achieve this task would be greatly appreciated.
Edit: While attempting to implement the solution provided earlier by @adriano009, I have encountered two issues:
Firstly, the LET scope is causing a bug in Safari, which states that I "can't create duplicate variable that shadows a global property". Therefore, I am utilizing VAR instead.
Secondly, when executing the following code:
jsScript += "var slides = document.getElementsByClassName('trList');";
jsScript += "for (let i = 0; i < slides.length; i++) {";
jsScript += "let attr = slides[i].getAttribute('onclick'); ";
jsScript += "console.log(attr);";
jsScript += "};" ;
Although there are onclick attributes listed in slides.item(i), the logs show that it found 0 attributes when attempting to retrieve them with slides[i].getAttribute('onclick'). What could be causing this issue?