Paulliev Posted March 5, 2021 Posted March 5, 2021 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!
rudi Posted March 5, 2021 Posted March 5, 2021 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!
Paulliev Posted March 5, 2021 Author Posted March 5, 2021 See the screenshot. De resultbox is the div and the div contains of anchors. I want to simply count the anchors in the div.
rudi Posted March 5, 2021 Posted March 5, 2021 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!
Paulliev Posted March 5, 2021 Author Posted March 5, 2021 A div is element in HTML. I'm using Webdriver UDF to automate chrome. So yes it is a webpage.
rudi Posted March 5, 2021 Posted March 5, 2021 Ah. So I'm the wrong person to help you, as I'm not familiar with Chrome automation at all. Sorry. Earth is flat, pigs can fly, and Nuclear Power is SAFE!
Paulliev Posted March 5, 2021 Author Posted March 5, 2021 No problem, sorry for the incomplete explanation that I use Webdriver UDF.
Danp2 Posted March 5, 2021 Posted March 5, 2021 @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. Latest Webdriver UDF Release Webdriver Wiki FAQs
Nine Posted March 5, 2021 Posted March 5, 2021 Showing the DOM can certainly help us understand what you are targeting for... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Paulliev Posted March 5, 2021 Author Posted March 5, 2021 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.
Paulliev Posted March 5, 2021 Author Posted March 5, 2021 @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>
Nine Posted March 5, 2021 Posted March 5, 2021 Try this : Local $iCount = _WD_ExecuteScript($sSession, 'return document.getElementById("myDIV").children.length;') MsgBox ($MB_SYSTEMMODAL, "", $iCount) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Paulliev Posted March 5, 2021 Author Posted March 5, 2021 @Nine Thank you for your help! You can just write javascript with Executescript, didn't know that yet.
Nine Posted March 5, 2021 Posted March 5, 2021 Yes it is really a powerful tool combine with a great UDF. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Danp2 Posted March 5, 2021 Posted March 5, 2021 I was thinking about adding this functionality to _WD_ElementActionEx so that you could easily get the child count for any element. Latest Webdriver UDF Release Webdriver Wiki FAQs
Paulliev Posted March 5, 2021 Author Posted March 5, 2021 @Danp2 Should be a cool feature tbh. I'm really happy with all your help guys! My project is almost finished, I'm blown away with all the possibilities with the webdriver.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now