jmp Posted October 22, 2019 Share Posted October 22, 2019 I found some code here : https://www.autoitscript.com/forum/topic/197413-how-to-fill-text-box-of-internet-explorer-by-reading-text/ I am tried to fill same type text box using this code, but i have also another scheme named with rice and i am tried to fill 0 in both Amount to take of KG : and Amount to take in Gram : (only in rice) using this code : expandcollapse popup#include <IE.au3> #include <MsgBoxConstants.au3> $oIE = _IEAttach ("Home") _IELoadWait($oIE) $iNumber = "Rice " Local $oStockKg = _IEGetObjById($oIE, "txtbuyingstockinkg0") Local $iOutStanding, $iKg, $iGram, $oStockKg, $oStockGram, $sStockKg, $sStockGram Local $oTds, $oTrs = _IETagNameGetCollection($oIE, "tr") If IsObj($oTrs) Then For $i = 1 To $oTrs.Length $oTr = $oTrs($i) $oTds = _IETagNameGetCollection($oTr, "td") If IsObj($oTds) And $oTds.Length = 5 Then $iOutStanding = $oTds(1).InnerText $iKg = StringLeft($iOutStanding, StringInStr($iOutStanding, ".")-1) $iGram = StringTrimLeft($iOutStanding, StringInStr($iOutStanding, ".")) $sStockKg = $oTds(3).FirstElementChild.getAttribute("id", 2) $oStockKg = _IEGetObjById($oIE, $sStockKg) $sStockGram = $oTds(4).FirstElementChild.getAttribute("id", 2) $oStockGram = _IEGetObjById($oIE, $sStockGram) If IsObj($oStockKg) Then If $oTds(0).InnerText = $iNumber Then MsgBox(0, "", "found") $oStockKg.Value = 0 If IsObj($oStockGram) Then $oStockGram.Value = 0 EndIf EndIf if $oStockKg.Value <> "" then ContinueLoop $oStockKg.Value = $iKg If IsObj($oStockGram) Then $oStockGram.Value = $iGram EndIf EndIf EndIf Next EndIf Now i have some questions : 1). Its Possible to short this code ? If Yes then how ? 2) What is use of IsObj in line 21, 25, 31 ? 3) Can i remove it from my script ? (Because it was also working without this) Link to comment Share on other sites More sharing options...
jmp Posted October 23, 2019 Author Share Posted October 23, 2019 @Subz Please help me about this topic. Link to comment Share on other sites More sharing options...
Subz Posted October 23, 2019 Share Posted October 23, 2019 A1. Why does the length of the code matter? A2. The lines are for error checking i.e. if the value isn't an object and you didn't have that line it would fail. A3. Sure you can remove error checking, it's not advised but if you really feel you need to shorten the code you can do that. Link to comment Share on other sites More sharing options...
jmp Posted October 24, 2019 Author Share Posted October 24, 2019 7 hours ago, Subz said: A1. Why does the length of the code matter? A2. The lines are for error checking i.e. if the value isn't an object and you didn't have that line it would fail. A3. Sure you can remove error checking, it's not advised but if you really feel you need to shorten the code you can do that. Because, i think i used some duplicate function in this code like If IsObj($oStockGram) Then In line 25 and 31. Link to comment Share on other sites More sharing options...
Subz Posted October 24, 2019 Share Posted October 24, 2019 Recommend you comment exactly what you want the code to do and then modify accordingly while updating the comments for example: expandcollapse popup#include <IE.au3> #include <MsgBoxConstants.au3> $oIE = _IEAttach ("Home") _IELoadWait($oIE) $sTd = "Rice " Local $oStockKg = _IEGetObjById($oIE, "txtbuyingstockinkg0") Local $iOutStanding, $iKg, $iGram, $oStockKg, $oStockGram, $sStockKg, $sStockGram Local $oTds, $oTrs = _IETagNameGetCollection($oIE, "tr") If IsObj($oTrs) Then For $i = 1 To $oTrs.Length $oTr = $oTrs($i) $oTds = _IETagNameGetCollection($oTr, "td") If IsObj($oTds) And $oTds.Length = 5 Then $iOutStanding = $oTds(1).InnerText $iKg = StringLeft($iOutStanding, StringInStr($iOutStanding, ".")-1) $iGram = StringTrimLeft($iOutStanding, StringInStr($iOutStanding, ".")) $sStockKg = $oTds(3).FirstElementChild.getAttribute("id", 2) $oStockKg = _IEGetObjById($oIE, $sStockKg) $sStockGram = $oTds(4).FirstElementChild.getAttribute("id", 2) $oStockGram = _IEGetObjById($oIE, $sStockGram) ;~ Check if $oStockKg is an object If IsObj($oStockKg) Then ;~ $oStockKg is an object ;~ Check if $oTds(index 0).InnerText equals $sTd (Rice) If $oTds(0).InnerText = $sTd Then ;~ $oTds(index 0).InnerText equals $sTd (Rice) ;~ MsgBox Found MsgBox(0, "", "found") ;~ Change $oStockKg.Value to 0 $oStockKg.Value = 0 ;~ Change $oStockGram.Value to 0 $oStockGram.Value = 0 ContinueLoop EndIf ;~ Check if $oStockKg.Value is not equal to "" If $oStockKg.Value <> "" then ContinueLoop ;~ $oStockKg.Value equals "" ;~ Change $oStockKg.Value to $iKg $oStockKg.Value = $iKg ;~ Check if $oStockGram is an object If IsObj($oStockGram) Then ;~ $oStockGram is an object ;~ Change $oStockGram.Value to $iGram $oStockGram.Value = $iGram EndIf EndIf EndIf Next EndIf 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