Jump to content

How to get id from webpage using innertext ?


 Share

Go to solution Solved by Danp2,

Recommended Posts

Hello,

How can i get id (PQtyA2) from webpage using innertext ?

 

HTML

<td><label for="">Name</label> <input name="RitemDetails[2].IsPartialQtyAllowed" id="PQtyA2" type="hidden" value="1" data-val-required="The IsPartialQtyAllowed field is required." data-val="true" data-val-number="The field IsPartialQtyAllowed must be a number."></td>

 

 

I tried with this but not showing anything

#include <IE.au3>
$oIE = _IEAttach ("Data Entry")
_IELoadWait($oIE)

Local $oTds = _IETagNameGetCollection ($oIE, "td")
For $oTd In $oTds
;~        MsgBox(0, "", $oTd.innertext)

 If $oTd.InnerText = "Name" Then
$findid = $oTd.NextElementSibling.id
    MsgBox(0, "", $findid)

EndIf
      Next

 

 

Edited by jmp
Link to comment
Share on other sites

Your post is lacking a few details --

  • I assume that the Name and ID of the Input element changes every time, correct?
  • It isn't clear if "not showing anything" means that the message box is blank or it doesn't appear at all

FWIW, your issue is probably related to this line --

$findid = $oTd.NextElementSibling.id

This is probably returning the adjacent TD element rather than the desired child element.

Try this instead --

$findid = _IETagNameGetCollection($oTd, 'input', 0)

Alternatively, you might try this --

$findid = $oTd.ChildNodes[1].id

 

Edited by Danp2
Typo
Link to comment
Share on other sites

@Danp2Thank you for reply

  • I assume that the Name and ID of the Input element changes every time, correct? - Yes
  • It isn't clear if "not showing anything" means that the message box is blank or it doesn't appear at all - Yes 

 

I tried with this line

$findid = _IETagNameGetCollection($oTd, 'input', 0)

But stil getting blank msgbox (my webpage have multiples 'input' tags)

 

i also try with it.

$findid = $oTd.ChildNoes[1].id

But getiing this error

Capture.PNG.bf50fe011ba97cfd488f6bd0487a085e.PNG

Link to comment
Share on other sites

Sorry my suggestions weren't helpful. To be fair, you've provided very little information that could help us to help you. Then you respond "Yes" when I seek additional details to know if the message box is blank or if it doesn't appear at all. How does answering Yes here provide any useful information? 🙁

Seems like not much has changed since here.

Link to comment
Share on other sites

 

 

4 minutes ago, Danp2 said:

Sorry my suggestions weren't helpful. To be fair, you've provided very little information that could help us to help you. Then you respond "Yes" when I seek additional details to know if the message box is blank or if it doesn't appear at all. How does answering Yes here provide any useful information? 🙁

Seems like not much has changed since here.

Sorry @Danp2 This is happening because I don't know English very well, I try to explain to you again.

 

My Webpage have multiple <td> and <input> tags lke this

<td><label for="">Surname</label> <input name="RitemDetails[3].IsPartialQtyAllowed" id="PQtyA3" type="hidden" value="1" data-val-required="The IsPartialQtyAllowed field is required." data-val="true" data-val-number="The field IsPartialQtyAllowed must be a number."></td>
<td><label for="">Name</label> <input name="RitemDetails[2].IsPartialQtyAllowed" id="PQtyA2" type="hidden" value="1" data-val-required="The IsPartialQtyAllowed field is required." data-val="true" data-val-number="The field IsPartialQtyAllowed must be a number."></td>
  • The Name and ID of the Input element changes every time.
  •  "Not showing anything" means that the message box is blank

 

Actually i want to search 'Name' text then find the id and delete it using 

.RemoveNode(True)
 
This is because I don't know English very well

 
 
Means
Me

image.png

Link to comment
Share on other sites

  • Solution
56 minutes ago, jmp said:

I tried with this line


$findid = _IETagNameGetCollection($oTd, 'input', 0)

But stil getting blank msgbox (my webpage have multiples 'input' tags)

That's because your MsgBox command is attempting to display an object. Try this instead --

MsgBox(0, "", $findid.id)

 

Link to comment
Share on other sites

50 minutes ago, Danp2 said:

That's because your MsgBox command is attempting to display an object. Try this instead --

MsgBox(0, "", $findid.id)

 

Thank you @Danp2 Its Working.

I have one another question Sometimes $oTd.InnerText is not equal to 'Name' (Some times random text added before Name) Then How can i use if $oTd.InnerText statement?

 

StringInStr helped me.

Edited by jmp
Solved!
Link to comment
Share on other sites

@jmp Then I can only assume that there's something wrong in your script. This is a modified version of your code which works for me --

#include <IE.au3>
$oIE = _IEAttach ("", "instance")
_IELoadWait($oIE)

Local $oLabels = _IETagNameGetCollection ($oIE, "label")

For $oLabel In $oLabels
       Consolewrite($oLabel.innertext & @CRLF)

     If $oLabel.InnerText = "Name" Then

        $findid = $oLabel.NextElementSibling.id
        MsgBox(0, "", $findid)
    EndIf
Next

 

Link to comment
Share on other sites

On 7/30/2021 at 9:06 PM, Danp2 said:

@jmp Then I can only assume that there's something wrong in your script. This is a modified version of your code which works for me --

#include <IE.au3>
$oIE = _IEAttach ("", "instance")
_IELoadWait($oIE)

Local $oLabels = _IETagNameGetCollection ($oIE, "label")

For $oLabel In $oLabels
       Consolewrite($oLabel.innertext & @CRLF)

     If $oLabel.InnerText = "Name" Then

        $findid = $oLabel.NextElementSibling.id
        MsgBox(0, "", $findid)
    EndIf
Next

 

Thanks @Danp2 But i have two questions

1. This will be able to find faster than Td tag?

2. What is use of this Line ? Because its working without this line

Consolewrite($oLabel.innertext & @CRLF)
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...