Jump to content

Loop trough div element and count children with AutoIT


Recommended Posts

Hello guys,

I can't find any examples of a loop in AutoIT where you count the children elements of a div. My div is a search result box and gives an anchor as 1 result. So I want to count the results, and later on I want to compare different searches counts. How do I simply loop through a div and find the children and count it. Thanks in advance!

Link to comment
Share on other sites

Hi,

what is a "div", what "search result box" do you talk about, same for "anchor"?

Maybe some examples would be helpful to get, what you need?

 

CU, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

What the hell is a "div" -- sorry, I don't get it 😣

Is that a screenshot you show a dialog presented by some EXE? Which EXE? Or maybe a web page?

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

@Paulliev You should check the wiki FAQ (see #7) for some ideas that may help you with this task.

FWIW, there are usually multiple ways to solve any problem, so the more we know about your situation then the better we are able to assist you. A web search with the proper search criteria can yield a bonanza of information, albeit generally not AutoIt specific. Once you find a generic solution, it can generally be translated into AutoIt.

Link to comment
Share on other sites

You have the div with display: none; if there are no results, All the anchors you see on the screenshots are results of the search in a input before. Can I somehow count how many anchors there are in the div['suggestions_corc_id'] are. I search for a children function but have nothing found yet.

 

image.png.e952ef71b4097a0d051c889afd300ce7.png

Link to comment
Share on other sites

@Danp2 Thanks for your feedback, I googled some stuff and found the exact result I want in Javascript. I found a function in autoIT which is called getElementById but it says it is not a valid function. See below the Javascript solution.

<!DOCTYPE html>
<html>
<head>
<style>
div {
  border: 1px solid black;
  margin: 5px;
}
</style>
</head>
<body>

<p>Click the button to find out how many children the div element below has.</p>

<button onclick="myFunction()">Try it</button>

<div id="myDIV">
  <a>First p element (index 0)</a>
  <a>Second p element (index 1)</a>
  <a>First p element (index 0)</a>
  <a>Second p element (index 1)</a>
</div>

<p id="demo"></p>

<script>
function myFunction() {
  var c = document.getElementById("myDIV").children.length;
  document.getElementById("demo").innerHTML = c;
}
</script>

</body>
</html>

 

Link to comment
Share on other sites

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...