Jump to content

Recommended Posts

Posted

I have a page with several hundred <div>s, and each <div> has several hundred child <div>s, each with their own children

when I use _IETagNameGetCollection($ie, "div", 0) I get them all, but I need to find a way to get say the 3rd child of the 5th child of the second top level <div>

I have not yet been able to find anything along this line

Is there any way to determine if an element is a child, parent, sibling?

Thank you

Posted

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Hi @HudsonKane.

One of these examples might help

#include <IE.au3>

Global $oIE = _IECreate("https://www.autoitscript.com/forum/topic/187409-ie-dom-siblings-and-children/", 1)

Example01()
Example02()
Example03()

Func Example01()
    Local $oItem = $oIE.document.getElementById("elComment_1346150")
    If (Not IsObj($oItem)) Or (Not ($oItem.children.length>1)) Then Return
    $oItem.children(1)
    If (Not IsObj($oItem)) Or (Not ($oItem.children.length>0)) Then Return
    $oItem.children(0)
    If Not IsObj($oItem) Then Return
    ConsoleWrite("Example01 found a complete match"&@CRLF)
EndFunc

Func Example02()
    Local $oItem = $oIE.document.body
    If (Not IsObj($oItem)) Or (Not ($oItem.children.length>0)) Then Return
    $oItem = $oItem.children(0)
    If (Not IsObj($oItem)) Or (Not ($oItem.children.length>0)) Then Return
    $oItem = $oItem.children(0)
    If Not IsObj($oItem) Then Return
    ConsoleWrite("Example02 found a complete match"&@CRLF)
EndFunc

Func Example03()
    Local $oItem = $oIE.document
    If (Not IsObj($oItem)) Then Return
    $oItems = $oItem.querySelectorAll("div>div:nth-of-type(5)>div:nth-of-type(1)");to use the retusn use length property and $oItems($i)
    If (Not IsObj($oItem)) Or $oItem.length=0 Then Return
    ConsoleWrite("Example03 found a complete match"&@CRLF)
EndFunc

 

Posted

Thank you, I didn't realize I could use querySelectorAll().  I am new to this and having an issue

this gives me the html I expect 

$a = $ie.document.getElementById("main_div_id")
ConsoleWrite($a.outerHtml)

but both of these yield empty html

$a = $ie.querySelectorAll("#main_div_id > div:nth-of-type(1)")
ConsoleWrite($a.outerHtml)
or
$a = $ie.document.getElementById("main_div_id")
If (IsObj($a)) Then
    Local $b = $a.querySelectorAll("div:nth-of-type(1)")
    If IsObj($b) Then
       ConsoleWrite($b.outerHtml)
    EndIf
EndIf

 

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
×
×
  • Create New...