Jump to content

How to handle error properly?


Recommended Posts

Referring to following coding, there are 2 cases for testing:

Case 1 when I tried this approach "_IEAction($oInput, "focus")" and get error as shown below

Shop9.png

 

Case 2

Furthermore, when I tried another approach, the suggested lists cannot pop up as shown on below image.

Shop12.png

Does anyone have any suggestions on what wrong it is and how to handle those error properly?
Thanks in advance for any suggestions

 

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <IE.au3>
; Create a constant variable in Local scope of the filepath that will be read/written to.
; Local Const $sFilePath = _WinAPI_GetTempFileName(@TempDir
Local $oButtons
Local $oIE = _IECreate("https://shopee.com.my/")
Sleep(5000)
Local $oDivs = _IETagNameGetCollection($oIE, "div")
   For $oDiv In $oDivs
       If $oDiv.ClassName = "language-selection__list" Then
            $oButtons = _IETagNameGetCollection($oDiv, "button")
            For $oButton In $oButtons
               If $oButton.InnerText = "English" Then
                   _IEAction($oButton, "click")
                   ExitLoop 2
               EndIf
            Next
       EndIf
   Next
Sleep(5000)
Local $sSendKey = "k"
Local $sSearch = ""
    ;==========================================================================
    ;Case 1
    Local $oInputs = _IETagNameGetCollection($oIE, "input")
    _IEAction($oInputs, "focus")
    ControlSend(_IEPropertyGet($oInputs, "title"), "", "", $sSendKey)
    Sleep(2000)
    ControlSend(_IEPropertyGet($oInputs, "title"), "", "", "{DOWN}")
    Sleep(2000)
    Local $oDivs = _IETagNameGetCollection($oInputs, "a")
    ;==========================================================================
    ;Case 2
    ;Local $oInputs = _IETagNameGetCollection($oIE, "input")
    ;For $oInput In $oInputs
      ;If StringInStr($oInput.ClassName, "shopee-searchbar-input__input") Then;
           ;$oInput.Value = "k"
           ;ExitLoop
      ;EndIf
    ;Next
    ;==========================================================================
 Sleep(3000)
For $oDiv In $oDivs
    If StringInStr($oDiv.ClassName, "shopee-searchbar-hints__entry__product-name") Then $sSearch &= StringStripWS($oDiv.Innertext, 7) & @CRLF
Next
MsgBox(32, "Search Items", $sSearch )

 

 

 

Edited by oemript
Link to post
Share on other sites
Local $oInputs = _IETagNameGetCollection($oIE, "input")
_IEAction($oInputs, "focus")

You showed two different versions of this code. The first (in the image), you showed $oInput (without the 's'), so this variable wouldn't exist at that stage. In the above example, you have a collection of objects ($oInputs) that you are trying to pass to the function, _IEAction. You can't pass a collection into this function. Instead, you need to process the collection with a For loop.

Link to post
Share on other sites
Local $oDivs = _IETagNameGetCollection($oInputs, "a")
For $oDiv In $oDivs
    If StringInStr($oDiv.ClassName, "shopee-searchbar-hints__entry__product-name") Then $sSearch &= StringStripWS($oDiv.Innertext, 7) & @CRLF
Next

Again, the code in the image doesn't match the posted code. Which one is correct? How do you know a match is being found? Try rewriting the code like this --

$oLinks = _IETagNameGetCollection($oIE, "a")
For $oLink In $oLinks
    If StringInStr($oLink.ClassName, "shopee-searchbar-hints__entry__product-name") Then 
        ConsoleWrite('Found matching link!' & @CRLF)
        $sSearch &= StringStripWS($oLink.Innertext, 7) & @CRLF
    EndIf
Next

 

Link to post
Share on other sites
28 minutes ago, oemript said:

Do you have any suggestions?

Yes, go back and reread my prior response.

1 hour ago, Danp2 said:

you have a collection of objects ($oInputs) that you are trying to pass to the function, _IEAction. You can't pass a collection into this function. Instead, you need to process the collection with a For loop.

 

Link to post
Share on other sites
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <IE.au3>
; Create a constant variable in Local scope of the filepath that will be read/written to.
; Local Const $sFilePath = _WinAPI_GetTempFileName(@TempDir
Local $oButtons
Local $oIE = _IECreate("https://shopee.com.my/")
Sleep(5000)
Local $oDivs = _IETagNameGetCollection($oIE, "div")
   For $oDiv In $oDivs
       If $oDiv.ClassName = "language-selection__list" Then
            $oButtons = _IETagNameGetCollection($oDiv, "button")
            For $oButton In $oButtons
               If $oButton.InnerText = "English" Then
                   _IEAction($oButton, "click")
                   ExitLoop 2
               EndIf
            Next
       EndIf
   Next
Sleep(5000)
Local $sSendKey = "k"
Local $oInputs = _IETagNameGetCollection($oIE, "input")
For $oInput In $oInputs
    If StringInStr($oInput.ClassName, "searchbar-input") Then
        _IEAction($oInput, "focus")
        ControlSend(_IEPropertyGet($oIE, "title"), "", "", $sSendKey)
        Sleep(2000)
        _IEAction($oInput, "click")
        Sleep(2000)
        ExitLoop
    EndIf
Next

Local $oLinks = _IETagNameGetCollection($oIE, "a")
Sleep(3000)
For $oLink In $oLinks
    If StringInStr($oLink.ClassName, "shopee-searchbar-hints") Then $sSearch &= StringStripWS($oLink.Innertext, 7) & @CRLF
Next
MsgBox(32, "Search Items", $sSearch )

 

Link to post
Share on other sites
10 hours ago, Subz said:
expandcollapsepopup
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <IE.au3>
; Create a constant variable in Local scope of the filepath that will be read/written to.
; Local Const $sFilePath = _WinAPI_GetTempFileName(@TempDir
Local $oButtons
Local $oIE = _IECreate("https://shopee.com.my/")
Sleep(5000)
Local $oDivs = _IETagNameGetCollection($oIE, "div")
   For $oDiv In $oDivs
       If $oDiv.ClassName = "language-selection__list" Then
            $oButtons = _IETagNameGetCollection($oDiv, "button")
            For $oButton In $oButtons
               If $oButton.InnerText = "English" Then
                   _IEAction($oButton, "click")
                   ExitLoop 2
               EndIf
            Next
       EndIf
   Next
Sleep(5000)
Local $sSendKey = "k"
Local $oInputs = _IETagNameGetCollection($oIE, "input")
For $oInput In $oInputs
    If StringInStr($oInput.ClassName, "searchbar-input") Then
        _IEAction($oInput, "focus")
        ControlSend(_IEPropertyGet($oIE, "title"), "", "", $sSendKey)
        Sleep(2000)
        _IEAction($oInput, "click")
        Sleep(2000)
        ExitLoop
    EndIf
Next

Local $oLinks = _IETagNameGetCollection($oIE, "a")
Sleep(3000)
For $oLink In $oLinks
    If StringInStr($oLink.ClassName, "shopee-searchbar-hints") Then $sSearch &= StringStripWS($oLink.Innertext, 7) & @CRLF
Next
MsgBox(32, "Search Items", $sSearch )

 

I am very appreciated for all your help
Thanks, to everyone very much for any suggestions (^v^)

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...