Jump to content

How to fill text box of internet explorer by reading text?


naru
 Share

Recommended Posts

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)

 

Capture.jpg

Link to comment
Share on other sites

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

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

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.

Capture1.JPG

Link to comment
Share on other sites

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 by Nareshm
i Understand this.
Link to comment
Share on other sites

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

 

Capture55.JPG

Link to comment
Share on other sites

@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 :

#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

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