Jump to content
yffulf

[Solved]how to get info from exist web

Recommended Posts

Posted (edited)

I find many example about to get tag name, fill form in IE, but there always has a _IEcreate or something..
if I don't want to open a new one, just use exists web,   what command can I use?

Edited by yffulf

Share this post


Link to post
Share on other sites

Hi @yffulf, and welcome to the AutoIt forums :welcome:

36 minutes ago, yffulf said:

if I don't want to open a new one, just use exists web,   what command can I use?

Look at _IEAttach() in the Help file :)


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites

@yffulf

If you need any help, don't be shy, and post your code with your questions :)


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites

Thanks a lot, now i have a problem, I use these command to press a button,

but the instance of page will change sometime, is there a way to get instance as a variable?

I know there is a ControlGetHandle, can it replace class and instance?

 

$submit = _IEGetObjByName($form,"btn_OK")
$hWnd = _IEPropertyGet($oIE, "hwnd")
_IEAction($Submit, "focus")
ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")

Share this post


Link to post
Share on other sites
Posted (edited)

@yffulf

Use directly

_IEAction($Submit, "click")

:)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
Posted (edited)

Thanks, but I found the instance change because I press F12.......lol

now I don't know why my script will stop during running due to "Variable used without being declared" or "The requested action with this object has failed."

sometimes my for loop can run 10 times, sometimes 15 times...then it will interrupt.

I guess it might be delay or lag of internet, and ie is not ready when I get object from it ?

how can i do to confirm the object is existed before i get it?

 

I try to add _IEloadwait after _IEattach it still happended,

so it might not cause by delay?

Edited by yffulf

Share this post


Link to post
Share on other sites

@yffulf

Post the whole code, so we can take a look and (try to) suggest you the best thing to do :)


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
Posted (edited)
#include <IE.au3>
#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <Excel.au3>
#include <SQLite.au3>

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")    ; Initialize a COM error handler
Func MyErrFunc(); This is my custom defined error handler
  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"    & @CRLF  & @CRLF & _
             "err.description is: " & @TAB & $oMyError.description  & @CRLF & _
             "err.windescription:"   & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "       & @TAB & hex($oMyError.number,8)  & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "   & @TAB & $oMyError.scriptline   & @CRLF & _
             "err.source is: "       & @TAB & $oMyError.source       & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile     & @CRLF & _
             "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            )
Endfunc


Global Static $g__sSQliteDll = _SQLite_Startup(); -- turn on the sql engine --------------------
Global Static $hDb = _SQLite_Open(); -- open a 'memory' DB --
Func _IsInList($Target, $List)
    Local $aMyResult, $iMyRows, $iMyColumns
    _SQLite_GetTable(-1, "SELECT " & $Target & " IN (" & $List & ");", $aMyResult, $iMyRows, $iMyColumns)
    Return 1 = $aMyResult[UBound($aMyResult) - 1]
 EndFunc   ;==>_IsInList


Local $oExcel = _Excel_Open()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
Local $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\10806.xlsx")
If @error Then
    MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example", "Error opening workbook '" & @ScriptDir & "\10806.xls" & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    _Excel_Close($oExcel)
    Exit
EndIf


Local $aResultName = _Excel_RangeRead($oWorkbook, Default, "A5:A10", 1)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example 3", "Error reading from workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
;~ _ArrayDisplay($aResultName, "Excel UDF: _Excel_RangeRead Example 3 - Formulas in column A")
Local $iRows = UBound($aResultName, $UBOUND_ROWS)
;~ MsgBox(0," ",$iRows)

Local $aResultDate = _Excel_RangeRead($oWorkbook, Default, "D5:AH10", 1)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example 3", "Error reading from workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
;~ _ArrayDisplay($aResultDate, "Excel UDF: _Excel_RangeRead Example 3 - Formulas in column A")
Local $iCols = UBound($aResultDate, $UBOUND_COLUMNS)
;~ MsgBox(0," ",$iCols)

Func Fillform()
       $oIE = _IEAttach("http://ela.tra.gov.tw/la/Overtime/OT1100_New.aspx?ID=A","url")
       _IELoadWait($oIE)

       $oForm = _IEFormGetObjByName($oIE, "form1")

       $oQuery = _IEFormElementGetObjByName($oForm, "tbx_DELAY_DATE");延時日期
           Do 
          Sleep(10)
       Until IsObj($oQuery)
       _IEFormElementSetValue($oQuery, $sVar)

       $oSelect = _IEFormElementGetObjByName($oForm, "ddl_DELAY_TYPE");延時類別
               Do 
          Sleep(10)
       Until IsObj($oSelect)
       _IEAction($oSelect, "focus")
       _IEFormElementOptionSelect($oSelect, $sVar2,1, "byValue")

       $oSelect2 = _IEFormElementGetObjByName($oForm, "ddl_DELAY_REASON");延時原因
               Do 
          Sleep(10)
       Until IsObj($oSelect2)
       _IEAction($oSelect, "focus")
       _IEFormElementOptionSelect($oSelect2, $sVar3,1, "byValue")

       $oQuery2 = _IEFormElementGetObjByName($oForm, "tbx_DELAY_NUM");延時時數
               Do 
          Sleep(10)
       Until IsObj($oQuery2)
       _IEFormElementSetValue($oQuery2, $sVar4)


       $oSubmit = _IEGetObjByName($oIE, "btn_AddItem");新增延時明細
       Do 
          Sleep(10)
       Until IsObj($oSubmit)
       $hWnd = _IEPropertyGet($oIE, "hwnd")
       _IEAction($oSubmit, "focus")
       Sleep($time)
       ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")
       WinWait("", "新增明細會異動主檔資料,確定新增嗎?")
       Sleep($time)
       ControlClick("", "新增明細會異動主檔資料,確定新增嗎?", "[CLASS:Button; TEXT:確定; Instance:1]")
       Sleep($time)
EndFunc
Func Searchname()
       $oIE = _IEAttach("http://ela.tra.gov.tw/la/Overtime/OT1100_New.aspx?ID=A","url")
       _IELoadWait($oIE)

       $oForm = _IEFormGetObjByName($oIE, "form1")
       _IEImgClick($oIE,"http://ela.tra.gov.tw/la/images/search.png","src")
       $oIE = _IEAttach("http://ela.tra.gov.tw/la/PublicPage/SRC_BC0010.aspx?CrID=tbx_EMP_NO&ReloadID=lbtn_EMP&PGID=OT1100","url")
       _IELoadWait($oIE)
       Local $oform =_IEFormGetObjByName($oIE,"form1")
       Local $Querry = _IEFormElementGetObjByName($oform,"tbx_Src_EMP_CNAME")
       _IEFormElementSetValue($Querry, $aResultName[$iname])
       $submit = _IEGetObjByName($oform,"btn_OK")
       $hWnd = _IEPropertyGet($oIE, "hwnd")
       _IEAction($Submit, "focus")
       ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")
       $oIE = _IEAttach("http://ela.tra.gov.tw/la/PublicPage/SRC_BC0010.aspx?CrID=tbx_EMP_NO&ReloadID=lbtn_EMP&PGID=OT1100","url")
       _IELoadWait($oIE)
       Local $oform =_IEFormGetObjByName($oIE,"form1")
       $submit = _IEGetObjByName($oform,"gv_Info$ctl03$ibtn_Modify")
       $hWnd = _IEPropertyGet($oIE, "hwnd")
       _IEAction($Submit, "focus")
       ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")
       Sleep(500)
EndFunc
Local $holiday = InputBox ("請輸入國定假日", "日期用逗號隔開" & @CRLF & @CRLF &  "E.g. 2,7,15,24,30");國定假日日期
Local $time = 200

For $iname = 0 To $iRows-1 Step 1

Searchname()

   For $idate = 0 To $iCols-1 Step 1

      If $idate < 9 Then
      Local $sVar = "108/06/"&"0"&$idate+1;延時日期變數
      Else
      Local $sVar = "108/06/"&$idate+1;延時日期變數
      EndIf

      If _IsInList($idate+1, $holiday) Then
         Select
         Case $aResultDate[$iname][$idate] = "日"

            For $ia =1 To 3 Step 1
               If $ia = 1 Then
                Local $sVar2 = "C1";延時類別變數
                Local $sVar3 = "1";延時原因變數
                Local $sVar4 = "8";延時時數變數
               ElseIf $ia =2 Then
                Local $sVar2 = "C2";延時類別變數
                Local $sVar3 = "1";延時原因變數
                Local $sVar4 = "2";延時時數變數
               ElseIf $ia =3 Then
                Local $sVar2 = "C3";延時類別變數
                Local $sVar3 = "1";延時原因變數
                Local $sVar4 = "1";延時時數變數
               EndIf
;~           MsgBox(0," ","108/06/" & $idate+1 &"今天是日班"&"是國定假日"&$sVar&@CRLF&$sVar2&@CRLF&$sVar3&@CRLF&$sVar4)
Fillform()
             Next
         Case $aResultDate[$iname][$idate] = "夜"

            For $ia =1 To 4 Step 1
               If $ia = 1 Then
                Local $sVar2 = "C1";延時類別變數
                Local $sVar3 = "1";延時原因變數
                Local $sVar4 = "8";延時時數變數
               ElseIf $ia =2 Then
                Local $sVar2 = "C2";延時類別變數
                Local $sVar3 = "1";延時原因變數
                Local $sVar4 = "2";延時時數變數
               ElseIf $ia =3 Then
                Local $sVar2 = "C3";延時類別變數
                Local $sVar3 = "1";延時原因變數
                Local $sVar4 = "1";延時時數變數
               ElseIf $ia =4 Then
                Local $sVar2 = "G1";延時類別變數
                Local $sVar3 = "3";延時原因變數
                Local $sVar4 = "1";延時時數變數
               EndIf
;~           MsgBox(0," ","108/06/" & $idate+1 &"今天是夜班"&"是國定假日"&$sVar&@CRLF&$sVar2&@CRLF&$sVar3&@CRLF&$sVar4)
Fillform()
             Next

         Case $aResultDate[$iname][$idate] = "補"

            If _IsInList($idate+1, $holiday) Then
             Local $sVar2 = "C1";延時類別變數
             Local $sVar3 = "1";延時原因變數
             Local $sVar4 = "8";延時時數變數
            Else
            EndIf
;~          MsgBox(0," ","108/06/" & $idate+1 &"今天是補休"&"是國定假日"&$sVar&@CRLF&$sVar2&@CRLF&$sVar3&@CRLF&$sVar4)
Fillform()
         Case Else

         EndSelect

      Else
         Select
         Case $aResultDate[$iname][$idate] = "日"

            For $ia =1 To 2 Step 1
               If $ia = 1 Then
                Local $sVar2 = "A1";延時類別變數
                Local $sVar3 = "1";延時原因變數
                Local $sVar4 = "2";延時時數變數
               ElseIf $ia =2 Then
                Local $sVar2 = "A2";延時類別變數
                Local $sVar3 = "1";延時原因變數
                Local $sVar4 = "1";延時時數變數
               EndIf
;~           MsgBox(0," ","108/06/" & $idate+1 &"今天是日班"&"不是國定假日"&$sVar&@CRLF&$sVar2&@CRLF&$sVar3&@CRLF&$sVar4)
Fillform()
             Next
         Case $aResultDate[$iname][$idate] = "夜"

            For $ia =1 To 3 Step 1
               If $ia = 1 Then
                Local $sVar2 = "A1";延時類別變數
                Local $sVar3 = "1";延時原因變數
                Local $sVar4 = "2";延時時數變數
               ElseIf $ia =2 Then
                Local $sVar2 = "A2";延時類別變數
                Local $sVar3 = "1";延時原因變數
                Local $sVar4 = "1";延時時數變數
               ElseIf $ia =3 Then
                Local $sVar2 = "G1";延時類別變數
                Local $sVar3 = "3";延時原因變數
                Local $sVar4 = "1";延時時數變數
               EndIf
;~           MsgBox(0," ","108/06/" & $idate+1 &"今天是夜班"&"不是國定假日"&$sVar&@CRLF&$sVar2&@CRLF&$sVar3&@CRLF&$sVar4)
Fillform()
             Next
         Case $aResultDate[$iname][$idate] = "補"
;~          MsgBox(0," ","108/06/" & $idate+1 &"今天是補休"&"不是國定假日"&$sVar&@CRLF&$sVar2&@CRLF&$sVar3&@CRLF&$sVar4)
         Case Else

         EndSelect
      EndIf



   Next
Next
_SQLite_Shutdown()

Here is my code, it read data from excel and fill the form at IE.

I use error handler try to find out where is the problem, it gave me this:

"IE.au3 T3.0-2 Warning from function internal function __IEIsObjType, Cannot register internal error handler, cannot trap COM errors (Use _IEErrorHandlerRegister() to register a user error handler)"

but it not interrupt code running, until this came up:
"--> IE.au3 T3.0-2 Warning from function _IEGetObjByName, $_IESTATUS_NoMatch (Name: btn_AddItem, Index: 0)"

below are name in html, the button name "btn_AddItem" didn't change after error happened .....

image.thumb.png.f2be498623575d20a926beeb98a1934f.png

Edited by yffulf

Share this post


Link to post
Share on other sites

After I add code line by line, the code execute fine until I add this

$oSubmit = _IEGetObjByName($oIE, "btn_AddItem");新增延時明細

       If IsObj($oSubmit) Then
          MsgBox(0," ","a obj")
       Else
          MsgBox(0," ","not a obj")
          EndIf

At first is was ok, msgbox show "a obj" and code keep going,

after few times of loop, it interrupt but msgbox doesn't show"not a obj"

and console show :

>"D:\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\0031896\Documents\new3.au3"    
"D:\AutoIt3\Include\IE.au3" (1876) : ==> The requested action with this object has failed.:
If IsObj($oObject.document.GetElementsByName($sName).item($iIndex)) Then
If IsObj($oObject.document^ ERROR
>Exit code: 1    Time: 24.36

 

It seems that this is where the problem occurs....

Share this post


Link to post
Share on other sites
Posted (edited)

I try to use _IEGetObjById and _IETagNameGetCollection,

but still same issue...

I really don't know why...

Is it possible that the page will change ObjName or ID itself@@?

 

Thank forum I find answer:

 

Edited by yffulf

Share this post


Link to post
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

×
×
  • Create New...