Jump to content

How to use .RemoveNode in IE if multiple id Exists with same name ?


Recommended Posts

My html page have multiple id with same name, and I want to skip first one and delete second Line.

I tried with this code but it was removing first id/line

#include <IE.au3>
$oIE = _IEAttach ("Final Print")
$Drceiptdetails = _IEGetObjById($oIE, "receiptdetails")
$Dreceiptdetails.RemoveNode(True)
$Dprintdetails = _IEGetObjById($oIE, "printdetails")
$Dprintdetails.RemoveNode(True)
Exit

 

Edited by Nareshm
add id instead of name
Link to comment
Share on other sites

Maybe something like:

_DeleteNode($oIE, "div", "id", "printdetails", 2)

Func _DeleteNode($_oIEObj, $_sTagType, $_sAttribType, $_sAttribValue, $_iDelInstance = 1)
    Local $iTagInstance = 1
    Local $oTagNameColl = _IETagNameGetCollection($_oIEObj, $_sTagType)
    If IsObj($oTagNameColl) Then
        For $i = 0 To $oTagNameColl.length - 1
            If $oTagNameColl($i).getAttribute($_sAttribType) = $_sAttribValue Then
                If $iTagInstance = $_iDelInstance Then
                    $oTagNameColl($i).RemoveNode(True)
                    ExitLoop
                EndIf
                $iTagInstance += 1
            EndIf
        Next
    EndIf
EndFunc

 

Edited by Subz
Updated thanks @Nine
Link to comment
Share on other sites

1 hour ago, Nareshm said:

@Juvigy

i want to delete id 

Capture12.JPG

If the html page is yours (so you have the permissions to edit the code), you should alter the IDs to stop the infringement.

For a quick fix you can just change the first id temporarily to access the second one, sth like this:

#include <IE.au3>
$oIE = _IEAttach ("Final Print")
$Drceiptdetails1 = _IEGetObjById($oIE, "receiptdetails") ; get first object
$Drceiptdetails1.id = "receiptdetails1" ; change it's id
$Drceiptdetails = _IEGetObjById($oIE, "receiptdetails") ; get second object
$Dreceiptdetails.RemoveNode(True) ; remove it
$Drceiptdetails1.id = "receiptdetails" ; restore the first object's id
Exit

 

Link to comment
Share on other sites

1 minute ago, Dionysis said:

If the html page is yours (so you have the permissions to edit the code), you should alter the IDs to stop the infringement.

For a quick fix you can just change the first id temporarily to access the second one, sth like this:

#include <IE.au3>
$oIE = _IEAttach ("Final Print")
$Drceiptdetails1 = _IEGetObjById($oIE, "receiptdetails") ; get first object
$Drceiptdetails1.id = "receiptdetails1" ; change it's id
$Drceiptdetails = _IEGetObjById($oIE, "receiptdetails") ; get second object
$Dreceiptdetails.RemoveNode(True) ; remove it
$Drceiptdetails1.id = "receiptdetails" ; restore the first object's id
Exit

 

It's not my own html page.

Link to comment
Share on other sites

1 hour ago, Subz said:

Maybe something like:

_DeleteNode($oIE, "div", "id", "printdetails")

Func _DeleteNode($_oIEObj, $_sTagType, $_sAttribType, $_sAttribValue, $_iDelInstance = 2)
    Local $iTagInstance = 1
    Local $oTagNameColl = _IETagNameGetCollection($_oIEObj, $_sTagType)
    If IsObj($oTagNameColl) Then
        For $i = 0 To $oTagNameColl.length - 1
            If $oTagNameColl($i).getAttribute($_sAttribType) = $_sAttribValue Then
                If $iTagInstance = $_iDelInstance Then
                    $oTagNameColl($i).RemoveNode(True)
                EndIf
            EndIf
            $iTagInstance += 1
        Next
    EndIf
EndFunc

 

@Subz

it was not deleting anything

Link to comment
Share on other sites

14 minutes ago, Nareshm said:

@Dionysis

Error in line 4

 

Capture33.JPG

Yeah... I just changed your code, so maybe you meant $Dreceiptdetails instead of $Drceiptdetails.

 

I tried my code by changing the _IEGetObjById example to:

#include <IE.au3>
Local $oIE = _IE_Example("basic")
$temp = _IEGetObjById($oIE, "line1")
$temp.id = "line2" ;now we have two "line2" IDs
MsgBox(0,"body.innerHTML Before",_IETagNameGetCollection($oIE,"body",0).innerHTML)

Local $oDiv = _IEGetObjById($oIE, "line2") ; select the first object
$oDiv.id = "sthelse" ; change the first ID to something else
$oDiv2 = _IEGetObjById($oIE, "line2") ;select the second object
$oDiv2.RemoveNode(True)
$oDiv.id = "line2" ;restore the first object's ID
MsgBox(0,"body.innerHTML After",_IETagNameGetCollection($oIE,"body",0).innerHTML)
Exit

It works as it is, so you can run it and see what's different in your code.

Link to comment
Share on other sites

@Subz & @Dionysis

There was a small bug in subz code :

Func _DeleteNode($_oIEObj, $_sTagType, $_sAttribType, $_sAttribValue, $_iDelInstance = 1)
    Local $iTagInstance = 1
    Local $oTagNameColl = _IETagNameGetCollection($_oIEObj, $_sTagType)
    If IsObj($oTagNameColl) Then
        For $i = 0 To $oTagNameColl.length - 1
            If $oTagNameColl($i).getAttribute($_sAttribType) = $_sAttribValue Then
                If $iTagInstance = $_iDelInstance Then
                    $oTagNameColl($i).RemoveNode(True)
                    ExitLoop
                EndIf
                $iTagInstance += 1
            EndIf
        Next
    EndIf
EndFunc

Increment of $iTagInstance was misplaced...

Link to comment
Share on other sites

20 hours ago, Dionysis said:

Yeah... I just changed your code, so maybe you meant $Dreceiptdetails instead of $Drceiptdetails.

 

I tried my code by changing the _IEGetObjById example to:

#include <IE.au3>
Local $oIE = _IE_Example("basic")
$temp = _IEGetObjById($oIE, "line1")
$temp.id = "line2" ;now we have two "line2" IDs
MsgBox(0,"body.innerHTML Before",_IETagNameGetCollection($oIE,"body",0).innerHTML)

Local $oDiv = _IEGetObjById($oIE, "line2") ; select the first object
$oDiv.id = "sthelse" ; change the first ID to something else
$oDiv2 = _IEGetObjById($oIE, "line2") ;select the second object
$oDiv2.RemoveNode(True)
$oDiv.id = "line2" ;restore the first object's ID
MsgBox(0,"body.innerHTML After",_IETagNameGetCollection($oIE,"body",0).innerHTML)
Exit

It works as it is, so you can run it and see what's different in your code.

Example running Good but in my codeI get same error.

Edited by Nareshm
Link to comment
Share on other sites

16 hours ago, Nine said:

@Subz & @Dionysis

There was a small bug in subz code :

Func _DeleteNode($_oIEObj, $_sTagType, $_sAttribType, $_sAttribValue, $_iDelInstance = 1)
    Local $iTagInstance = 1
    Local $oTagNameColl = _IETagNameGetCollection($_oIEObj, $_sTagType)
    If IsObj($oTagNameColl) Then
        For $i = 0 To $oTagNameColl.length - 1
            If $oTagNameColl($i).getAttribute($_sAttribType) = $_sAttribValue Then
                If $iTagInstance = $_iDelInstance Then
                    $oTagNameColl($i).RemoveNode(True)
                    ExitLoop
                EndIf
                $iTagInstance += 1
            EndIf
        Next
    EndIf
EndFunc

Increment of $iTagInstance was misplaced...

@Nine Thank You But, it was Deleting first id not second.

Link to comment
Share on other sites

You would need to set the last parameter:

_DeleteNode($oIE, "div", "id", "printdetails", 2)

Func _DeleteNode($_oIEObj, $_sTagType, $_sAttribType, $_sAttribValue, $_iDelInstance = 1)
    Local $iTagInstance = 1
    Local $oTagNameColl = _IETagNameGetCollection($_oIEObj, $_sTagType)
    If IsObj($oTagNameColl) Then
        For $i = 0 To $oTagNameColl.length - 1
            If $oTagNameColl($i).getAttribute($_sAttribType) = $_sAttribValue Then
                If $iTagInstance = $_iDelInstance Then
                    $oTagNameColl($i).RemoveNode(True)
                    ExitLoop
                EndIf
                $iTagInstance += 1
            EndIf
        Next
    EndIf
EndFunc

 

Edited by Subz
Updated thanks @Nine
Link to comment
Share on other sites

Link to comment
Share on other sites

3 minutes ago, Nine said:

@Subz change your code, you still have $iTagInstance += 1 misplaced

Yes @Subz, Its Like This :

Func _DeleteNode($_oIEObj, $_sTagType, $_sAttribType, $_sAttribValue, $_iDelInstance = 2)
    Local $iTagInstance = 1
    Local $oTagNameColl = _IETagNameGetCollection($_oIEObj, $_sTagType)
    If IsObj($oTagNameColl) Then
        For $i = 0 To $oTagNameColl.length - 1
            If $oTagNameColl($i).getAttribute($_sAttribType) = $_sAttribValue Then
                If $iTagInstance = $_iDelInstance Then
                    $oTagNameColl($i).RemoveNode(True)
                    ExitLoop
                EndIf
                $iTagInstance += 1
            EndIf
        Next
    EndIf
EndFunc

 

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...