naru Posted January 18, 2019 Share Posted January 18, 2019 I want to fill Amount to take in kg and amount to take in gram using outstanding amount text. example : If Outstanding amount of Sugar is 2.450 then i want to fill amount to take in kg with 2 and amount to take in gram with 450 using autoit. same do with oil. Inspect Element : 8.000 : <td>8.000</td> Amount to take of KG : <input name="RitemDetails[0].buyingstockinkg" class="input-validation-error" id="txtbuyingstockinkg0" aria-invalid="true" aria-required="true" aria-describedby="txtbuyingstockinkg0-error" type="text" value="" data-val-required="kindly enter quantity in kg." data-val="true" autocomplete="off" data-val-range-min="0" data-val-range-max="9999" data-val-range="Entered Amount to take in KG should be Numeric and Specific Format." data-val-number="The field buyingstockinkg must be a number."> Amount to take in Gram : <input name="RitemDetails[0].buyingstockingm" id="txtbuyingstockingm0" type="text" value="" data-val-required="kindly enter quantity in gm." data-val="true" autocomplete="off" data-val-range-min="0" data-val-range-max="999" data-val-range="Entered Amount to take in Gram should be Numeric and Specific Format." data-val-number="The field buyingstockingm must be a number."> 2.450 : <td>2.450</td> Amount to take of KG : <input name="RitemDetails[1].buyingstockinkg" id="txtbuyingstockinkg1" type="text" value="" data-val-required="kindly enter quantity in kg." data-val="true" autocomplete="off" data-val-range-min="0" data-val-range-max="9999" data-val-range="Entered Amount to take in KG should be Numeric and Specific Format." data-val-number="The field buyingstockinkg must be a number."> Amount to take in Gram : <input name="RitemDetails[1].buyingstockingm" id="txtbuyingstockingm1" type="text" value="" data-val-required="kindly enter quantity in gm." data-val="true" autocomplete="off" data-val-range-min="0" data-val-range-max="999" data-val-range="Entered Amount to take in Gram should be Numeric and Specific Format." data-val-number="The field buyingstockingm must be a number."> I tried with this code, But it is filled all text (Like 8.000) into KG box : #include <IE.au3> Opt("TrayAutoPause",0) HotKeySet("{ESC}", "Quit") Func Quit() Exit EndFunc $oIE = _IEAttach ("Home") $body = _IEBodyReadHTML($oIE) Local $oil = "Oil", $ioil = "0" Local $oTds = _IETagNameGetCollection($oIE, "td") For $oTd In $oTds If $oTd.InnerText = $oil Then $ioil = $oTd.NextElementSibling.InnerText EndIf Next $oObj = _IEGetObjById($oIE,"txtbuyingstockinkg0") _IEPropertySet($oObj,"innertext", $ioil) Link to comment Share on other sites More sharing options...
Subz Posted January 18, 2019 Share Posted January 18, 2019 You almost have it just need to set the value while within the loop, something like: #include <IE.au3> Local $oIE = _IEAttach ("Home") Local $iOutStanding, $iKg, $iGram, $oStockKg, $oStockGram Local $oTds = _IETagNameGetCollection($oIE, "td") For $oTd In $oTds Switch $oTd.InnerText Case "Oil" $iOutStanding = $oTd.NextElementSibling.InnerText $iKg = StringLeft($iOutStanding, StringInStr($iOutStanding, ".")-1) $iGram = StringTrimLeft($iOutStanding, StringInStr($iOutStanding, ".")) $oStockKg = _IEGetObjById($oIE, "txtbuyingstockinkg0") $oStockKg.Value = $iKg $oStockGram = _IEGetObjById($oIE, "txtbuyingstockingm0") $oStockGram.Value = $iGram Case "Sugar" $iOutStanding = $oTd.NextElementSibling.InnerText $iKg = StringLeft($iOutStanding, StringInStr($iOutStanding, ".")-1) $iGram = StringTrimLeft($iOutStanding, StringInStr($iOutStanding, ".")) $oStockKg = _IEGetObjById($oIE, "txtbuyingstockinkg1") $oStockKg.Value = $iKg $oStockGram = _IEGetObjById($oIE, "txtbuyingstockingm1") $oStockGram.Value = $iGram EndSwitch Next Link to comment Share on other sites More sharing options...
naru Posted January 19, 2019 Author Share Posted January 19, 2019 Thanks @Subz But sometimes the tab of Sugar comes first and then the oil, when i run this code, the amount fill into the cross. Like Oil is 2.450 and Sugar is 8.000. Link to comment Share on other sites More sharing options...
Subz Posted January 19, 2019 Share Posted January 19, 2019 You should be able to use something like the following: #include <IE.au3> Local $oIE = _IEAttach ("Home") 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) 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) If IsObj($oStockKg) Then $oStockKg.Value = $iKg $sStockGram = $oTds(4).FirstElementChild.getAttribute("id", 2) $oStockGram = _IEGetObjById($oIE, $sStockGram) If IsObj($oStockGram) Then $oStockGram.Value = $iGram EndIf Next EndIf Link to comment Share on other sites More sharing options...
naru Posted January 19, 2019 Author Share Posted January 19, 2019 @Subz its Working, But error on line 11. Link to comment Share on other sites More sharing options...
Subz Posted January 19, 2019 Share Posted January 19, 2019 Sorry my crystal ball is broken, you need to be more specific, what is the error? When does it occur, is it before or after it fills out the form or during? Link to comment Share on other sites More sharing options...
naru Posted January 19, 2019 Author Share Posted January 19, 2019 47 minutes ago, Subz said: Sorry my crystal ball is broken, you need to be more specific, what is the error? When does it occur, is it before or after it fills out the form or during? @Subz I think error comes after fill out the form. Link to comment Share on other sites More sharing options...
Subz Posted January 19, 2019 Share Posted January 19, 2019 You may have a row with only one td (index would be 0) so you just check the number of cells(tds) within the row(trs). ;~ Replace If IsObj($oTds) Then ;~ With If IsObj($oTds) And $oTds.Length = 5 Then Link to comment Share on other sites More sharing options...
naru Posted January 19, 2019 Author Share Posted January 19, 2019 (edited) 3 hours ago, Subz said: You may have a row with only one td (index would be 0) so you just check the number of cells(tds) within the row(trs). ;~ Replace If IsObj($oTds) Then ;~ With If IsObj($oTds) And $oTds.Length = 5 Then @Subz Thank you very much. Edited January 19, 2019 by Nareshm i Understand this. Link to comment Share on other sites More sharing options...
naru Posted January 20, 2019 Author Share Posted January 20, 2019 (edited) @Subz How to check if input box is empty ? i want to run this code only when input box is empty. Edited January 20, 2019 by Nareshm Link to comment Share on other sites More sharing options...
Subz Posted January 20, 2019 Share Posted January 20, 2019 Example: If StringStripWS($oStockKg.Value, 8) = "" Then ... Link to comment Share on other sites More sharing options...
naru Posted January 20, 2019 Author Share Posted January 20, 2019 1 minute ago, Subz said: Exam ?ple: If StringStripWS($oStockKg.Value, 8) = "" Then ... What is 8 ? Link to comment Share on other sites More sharing options...
Subz Posted January 20, 2019 Share Posted January 20, 2019 Look up StringStripWS in help file. Link to comment Share on other sites More sharing options...
naru Posted January 20, 2019 Author Share Posted January 20, 2019 13 minutes ago, Subz said: Example: If StringStripWS($oStockKg.Value, 8) = "" Then ... @Subz Error in line 7. #include <IE.au3> Local $oIE = _IEAttach ("Home") $body = _IEBodyReadHTML($oIE) Local $iOutStanding, $iKg, $iGram, $oStockKg, $oStockGram, $sStockKg, $sStockGram Local $oTds, $oTrs = _IETagNameGetCollection($oIE, "tr") If StringStripWS($oStockKg.Value, 8) = "" Then 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) If IsObj($oStockKg) Then $oStockKg.Value = $iKg $sStockGram = $oTds(4).FirstElementChild.getAttribute("id", 2) $oStockGram = _IEGetObjById($oIE, $sStockGram) If IsObj($oStockGram) Then $oStockGram.Value = $iGram EndIf Next EndIf ElseIf $btnnext = _IEGetObjById($oIE,"btnnext") _IEAction($btnnext,"click") EndIf Link to comment Share on other sites More sharing options...
Subz Posted January 20, 2019 Share Posted January 20, 2019 The line I posted was an example. You would need to define the object of the input box, before using it, I've given you enough examples to show how to do this, so you need to take the time to figure it out. Link to comment Share on other sites More sharing options...
naru Posted January 20, 2019 Author Share Posted January 20, 2019 @Subz I tried to check input box using id but it showing wrong. #include <IE.au3> #include <MsgBoxConstants.au3> Local $oIE = _IEAttach ("Home") $body = _IEBodyReadHTML($oIE) Local $oDiv = _IEGetObjById($oIE, "txtbuyingstockinkg0") $stock = $oDiv.innertext if $stock = "" Then MsgBox($MB_SYSTEMMODAL, "Line1", "Text Box is empty") EndIf Link to comment Share on other sites More sharing options...
Subz Posted January 20, 2019 Share Posted January 20, 2019 #include <IE.au3> Local $oIE = _IEAttach ("Home") Local $oStockKg = _IEGetObjById($oIE, "txtbuyingstockinkg0") If IsObj($oStockKg) And StringStripWS($oStockKg.Value, 8) = "" Then MsgBox(4096, "Line1", "Text Box is empty") EndIf Link to comment Share on other sites More sharing options...
naru Posted January 21, 2019 Author Share Posted January 21, 2019 @Subz This code is working perfectly But webpage showing error when outstanding amount of sugar is in 0.XXX Format, like 0.742, 0.750, 0.650, etc. When i run this code Webpage showing "The amount of taking is greater than the remaining quantity." error and then reload page and input box is empty again. When i enter amount manualy no error showing. My Whole Code is : expandcollapse popup#include <IE.au3> HotKeySet("{ESC}", "Quit") Func Quit() Exit EndFunc $oIE = _IEAttach ("Home") _IELoadWait($oIE) Local $oStockKg = _IEGetObjById($oIE, "txtbuyingstockinkg0") If IsObj($oStockKg) And StringStripWS($oStockKg.Value, 8) = "" Then 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) If IsObj($oStockKg) Then $oStockKg.Value = $iKg $sStockGram = $oTds(4).FirstElementChild.getAttribute("id", 2) $oStockGram = _IEGetObjById($oIE, $sStockGram) If IsObj($oStockGram) Then $oStockGram.Value = $iGram EndIf Next $btnnext = _IEGetObjById($oIE,"btnnext") _IEAction($btnnext,"click") EndIf EndIf $btnnext = _IEGetObjById($oIE,"btnnext") _IEAction($btnnext,"click") _IELoadWait($oIE) Exit Link to comment Share on other sites More sharing options...
naru Posted January 26, 2019 Author Share Posted January 26, 2019 @Subz Please help me for above problem. Link to comment Share on other sites More sharing options...
Subz Posted January 26, 2019 Share Posted January 26, 2019 So is it putting in the correct amount into both fields? 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