Jump to content

How to count the number of times an error occurred on a webpage IE11 ?


jmp
 Share

Recommended Posts

I am trying to verify my customer using this code :

#include <IE.au3>
$oIE = _IEAttach ("My Webpage")
_IELoadWait($oIE)
$btnSelect = _IEGetObjById($oIE,"btnselect")
_IEAction($btnSelect,"click")
$btnsubmit = _IEGetObjById($oIE,"btnsubmit")
_IEAction($btnsubmit,"click")

while 1
_IELoadWait($oIE)
$body = _IEBodyReadHTML($oIE)
If StringInStr($body, "Verify Member") Then
$btnverify = _IEGetObjById($oIE,"btnverify")
_IEAction($btnverify,"click")
_IELoadWait($oIE)
$memberconsent = _IEGetObjById($oIE,"memberconsent")
_IEAction($memberconsent,"click")
_IELoadWait($oIE)
$imgverify = _IEGetObjById($oIE,"imgverify")
_IEAction($imgverify,"click")
EndIf
If StringInStr($body, "Verification Failed") Then
ContinueLoop
Else
$btnmeselect = _IEGetObjById($oIE,"btnmeselect")
_IEAction($btnmeselect,"click")
_IELoadWait($oIE)
exitloop
EndIf
WEnd

But i want to count number of times an error showing about verification failed. If verification failed more than 3 times then i want to exit my script.

Link to comment
Share on other sites

11 minutes ago, jmp said:

How can i put my code in this?  

 

#include <IE.au3>
$oIE = _IEAttach("My Webpage")
_IELoadWait($oIE)
$btnSelect = _IEGetObjById($oIE, "btnselect")
_IEAction($btnSelect, "click")
$btnsubmit = _IEGetObjById($oIE, "btnsubmit")
_IEAction($btnsubmit, "click")

Global $iErrorCounter = 0  

While $iErrorCounter < 3
    _IELoadWait($oIE)
    $body = _IEBodyReadHTML($oIE)
    If StringInStr($body, "Verify Member") Then
        $btnverify = _IEGetObjById($oIE, "btnverify")
        _IEAction($btnverify, "click")
        _IELoadWait($oIE)
        $memberconsent = _IEGetObjById($oIE, "memberconsent")
        _IEAction($memberconsent, "click")
        _IELoadWait($oIE)
        $imgverify = _IEGetObjById($oIE, "imgverify")
        _IEAction($imgverify, "click")
    EndIf
    
    If StringInStr($body, "Verification Failed") Then
        $iErrorCounter += 1
    Else
        $btnmeselect = _IEGetObjById($oIE, "btnmeselect")
        _IEAction($btnmeselect, "click")
        _IELoadWait($oIE)
        ExitLoop
    EndIf
WEnd

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

4 hours ago, Musashi said:

 

#include <IE.au3>
$oIE = _IEAttach("My Webpage")
_IELoadWait($oIE)
$btnSelect = _IEGetObjById($oIE, "btnselect")
_IEAction($btnSelect, "click")
$btnsubmit = _IEGetObjById($oIE, "btnsubmit")
_IEAction($btnsubmit, "click")

Global $iErrorCounter = 0  

While $iErrorCounter < 3
    _IELoadWait($oIE)
    $body = _IEBodyReadHTML($oIE)
    If StringInStr($body, "Verify Member") Then
        $btnverify = _IEGetObjById($oIE, "btnverify")
        _IEAction($btnverify, "click")
        _IELoadWait($oIE)
        $memberconsent = _IEGetObjById($oIE, "memberconsent")
        _IEAction($memberconsent, "click")
        _IELoadWait($oIE)
        $imgverify = _IEGetObjById($oIE, "imgverify")
        _IEAction($imgverify, "click")
    EndIf
    
    If StringInStr($body, "Verification Failed") Then
        $iErrorCounter += 1
    Else
        $btnmeselect = _IEGetObjById($oIE, "btnmeselect")
        _IEAction($btnmeselect, "click")
        _IELoadWait($oIE)
        ExitLoop
    EndIf
WEnd

@Musashi Can i get msgbox after error showed three times ?

i want to also add some code If verification failed 3 times.

Edited by jmp
add some code If verification failed 3 times
Link to comment
Share on other sites

15 minutes ago, FrancescoDiMuro said:

@jmp
What's wrong with opening the Help file and do the simple tasks you are asking for yourself?

@FrancescoDiMuro i am added line like this :

#include <IE.au3>
$oIE = _IEAttach("My Webpage")
_IELoadWait($oIE)
$btnSelect = _IEGetObjById($oIE, "btnselect")
_IEAction($btnSelect, "click")
$btnsubmit = _IEGetObjById($oIE, "btnsubmit")
_IEAction($btnsubmit, "click")

Global $iErrorCounter = 0  

While $iErrorCounter < 3
    _IELoadWait($oIE)
    $body = _IEBodyReadHTML($oIE)
    If StringInStr($body, "Verify Member") Then
        $btnverify = _IEGetObjById($oIE, "btnverify")
        _IEAction($btnverify, "click")
        _IELoadWait($oIE)
        $memberconsent = _IEGetObjById($oIE, "memberconsent")
        _IEAction($memberconsent, "click")
        _IELoadWait($oIE)
        $imgverify = _IEGetObjById($oIE, "imgverify")
        _IEAction($imgverify, "click")
    EndIf
    
    If StringInStr($body, "Verification Failed") Then
        $iErrorCounter += 1
    elseif $iErrorCounter = 3 then
    msgbox(0, "",  "Limit exceeded")
    ;something here
    Else
        $btnmeselect = _IEGetObjById($oIE, "btnmeselect")
        _IEAction($btnmeselect, "click")
        _IELoadWait($oIE)
        ExitLoop
    EndIf
WEnd

But i am not getting msgbox

Edited by jmp
Link to comment
Share on other sites

Sometimes it is helpful to reduce the code to the process logic, as @FrancescoDiMuro has already suggested :

Global $iErrorCounter   = 0
Global $bErrorCondition = False ; *** For this simulation only

While $iErrorCounter < 3
    ConsoleWrite('> ==> LOOP : $iErrorCounter = ' & $iErrorCounter  & @CRLF)

    ; [CODE...]

    $bErrorCondition = True ; Simulates --> Verification Failed
    If $bErrorCondition Then
        $iErrorCounter += 1
        ConsoleWrite('! $iErrorCounter + 1 : $iErrorCounter = ' & $iErrorCounter  & @CRLF)
    Else
        ; Less than 3 Errors :
        ; [CODE...]
        ExitLoop
    EndIf
WEnd

if $iErrorCounter = 3 Then
    MsgBox(0, 'Error : ', 'Limit of three errors reached')
    ; Insert additional code here
EndIf

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

7 hours ago, Musashi said:

Sometimes it is helpful to reduce the code to the process logic, as @FrancescoDiMuro has already suggested :

Global $iErrorCounter   = 0
Global $bErrorCondition = False ; *** For this simulation only

While $iErrorCounter < 3
    ConsoleWrite('> ==> LOOP : $iErrorCounter = ' & $iErrorCounter  & @CRLF)

    ; [CODE...]

    $bErrorCondition = True ; Simulates --> Verification Failed
    If $bErrorCondition Then
        $iErrorCounter += 1
        ConsoleWrite('! $iErrorCounter + 1 : $iErrorCounter = ' & $iErrorCounter  & @CRLF)
    Else
        ; Less than 3 Errors :
        ; [CODE...]
        ExitLoop
    EndIf
WEnd

if $iErrorCounter = 3 Then
    MsgBox(0, 'Error : ', 'Limit of three errors reached')
    ; Insert additional code here
EndIf

 

@Musashi Why the code needs to be reduced ?

As @FrancescoDiMuro has suggested, I have written the code for msgbox outside the while loop, and it was working for me.

#include <IE.au3>
$oIE = _IEAttach("My Webpage")
_IELoadWait($oIE)
$btnSelect = _IEGetObjById($oIE, "btnselect")
_IEAction($btnSelect, "click")
$btnsubmit = _IEGetObjById($oIE, "btnsubmit")
_IEAction($btnsubmit, "click")

Global $iErrorCounter = 0  

While $iErrorCounter < 3
    _IELoadWait($oIE)
    $body = _IEBodyReadHTML($oIE)
    If StringInStr($body, "Verify Member") Then
        $btnverify = _IEGetObjById($oIE, "btnverify")
        _IEAction($btnverify, "click")
        _IELoadWait($oIE)
        $memberconsent = _IEGetObjById($oIE, "memberconsent")
        _IEAction($memberconsent, "click")
        _IELoadWait($oIE)
        $imgverify = _IEGetObjById($oIE, "imgverify")
        _IEAction($imgverify, "click")
    EndIf
    
    If StringInStr($body, "Verification Failed") Then
        $iErrorCounter += 1
    Else
        $btnmeselect = _IEGetObjById($oIE, "btnmeselect")
        _IEAction($btnmeselect, "click")
        _IELoadWait($oIE)
        ExitLoop
    EndIf
WEnd

If $iErrorCounter = 3 then
    msgbox(0, "",  "Limit has been reached")
    ;something here
Endif

 

Edited by jmp
Link to comment
Share on other sites

7 hours ago, jmp said:

@Musashi Why the code needs to be reduced ?

Your problem with the messagebox was easy to solve ( @FrancescoDiMuro told you what's to do ;))

Now imagine, you have a more complex, nested structure with various While.. , If...ElseIf...Else , Select...Case..., Switch... and so on. To analyze, whether these conditions are being executed or not, it is often easier to use the process logic without the complete additional code. In such cases reducing the code can serve the purpose of traceability.
For troubleshooting, it's more of a downside to show a section with i.e. 100 lines, that will not be processed anyway.

Use Consolewrites and replace required function results with dummies.

Edited by Musashi

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

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