My main goal is to automatically click on all the links present on a web page and then close any tabs that open up as a result. The structure of these links is like this:
<ul>
<li>
<a href=#>random text</a>
</li>
<li>...
Since there are multiple links to interact with, I attempted the following approach:
Click All Links
Set Global Variable ${i} 1
${elementCount}= Execute Javascript return document.querySelectorAll('a').length
FOR ${i} IN RANGE ${elementCount}
Execute Javascript document.getElementsByTagName('a')[i].click();
Run Keyword and Ignore Error Delete Tab
Exit For Loop If ${i} == elementCount
END
Log Exited
Delete Tab
Sleep ${Delay_short}
${title_var} Get Window Titles
Select Window title=${title_var}[1]
Close Window
However, I am facing an issue where I cannot progress beyond retrieving the initial length of zero for ${elementCount}:
Executing JavaScript:
return document.querySelectorAll('a').length
Without any arguments.
20210104 10:20:26.687 : INFO : ${elementCount} = 0
I would greatly appreciate any guidance or assistance in resolving this matter.