jmp Posted July 30, 2021 Share Posted July 30, 2021 (edited) 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 July 30, 2021 by jmp Link to comment Share on other sites More sharing options...
Danp2 Posted July 30, 2021 Share Posted July 30, 2021 (edited) 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 July 30, 2021 by Danp2 Typo Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
jmp Posted July 30, 2021 Author Share Posted July 30, 2021 @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 Link to comment Share on other sites More sharing options...
Danp2 Posted July 30, 2021 Share Posted July 30, 2021 Sorry... that should be "ChildNodes" instead. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
jmp Posted July 30, 2021 Author Share Posted July 30, 2021 1 minute ago, Danp2 said: Sorry... that should be "ChildNodes" instead. Link to comment Share on other sites More sharing options...
Danp2 Posted July 30, 2021 Share Posted July 30, 2021 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. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
jmp Posted July 30, 2021 Author Share Posted July 30, 2021 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 Link to comment Share on other sites More sharing options...
Solution Danp2 Posted July 30, 2021 Solution Share Posted July 30, 2021 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) Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
jmp Posted July 30, 2021 Author Share Posted July 30, 2021 (edited) 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 July 30, 2021 by jmp Solved! Link to comment Share on other sites More sharing options...
Danp2 Posted July 30, 2021 Share Posted July 30, 2021 Since the text actually belongs to the Label element, I would suggest that you try processing those instead of the TD elements. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
jmp Posted July 30, 2021 Author Share Posted July 30, 2021 56 minutes ago, Danp2 said: Since the text actually belongs to the Label element, I would suggest that you try processing those instead of the TD elements. @Danp2 How? Link to comment Share on other sites More sharing options...
Danp2 Posted July 30, 2021 Share Posted July 30, 2021 @jmpThe same way that you process TD or any other elements. 😏 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
jmp Posted July 30, 2021 Author Share Posted July 30, 2021 23 minutes ago, Danp2 said: @jmpThe same way that you process TD or any other elements. 😏 @Danp2 i tried label instead of Td but i think it's not working, getting blank msgbox. • I changed only td to label Link to comment Share on other sites More sharing options...
Danp2 Posted July 30, 2021 Share Posted July 30, 2021 @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 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
jmp Posted August 2, 2021 Author Share Posted August 2, 2021 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 More sharing options...
Danp2 Posted August 2, 2021 Share Posted August 2, 2021 It should be roughly the same speed since you should be looping through the same number of elements. It will be more accurate, which is why I suggested switching to Label elements. You can comment out the ConsoleWrite line if you wish. It is there strictly for debugging purposes. jmp 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
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