Best way to avoid an error if an Internet Explorer Element is not found

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
diamondrail
Junior Coder
Posts: 20
Joined: Wed Jul 31, 2019 9:38 am

Best way to avoid an error if an Internet Explorer Element is not found

Post by diamondrail » Tue Oct 29, 2019 5:43 pm

I have a situation where I need an element to be clicked, however, if that element is not shown on the page, I want the script to continue without an error. (Usually getting an error because the script cannot find the IE element).

What type of If statement do I need to use, can someone assist me with this? Please show me with the below example.

Example:


// Change "O" to H to extract inner html, T for just text. O is outer html - i.e. everything. Matches returned in valueArray
IEGetTagsByAttrib>{"https://www.google.ca/#spf=157237097133 ... valueArray

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 628
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Best way to avoid an error if an Internet Explorer Element is not found

Post by Dorian (MJT support) » Tue Oct 29, 2019 11:22 pm

I just responded to this question via your support ticket, as your question there contained more specifics.
Yes, we have a Custom Scripting Service. Message me or go here

User avatar
PepsiHog
Automation Wizard
Posts: 444
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Re: Best way to avoid an error if an Internet Explorer Element is not found

Post by PepsiHog » Wed Nov 20, 2019 4:50 pm

@Dorian,
Oh, sure, Dorian, just keep it a secret, why don't you. :lol:

PepsiHog
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2020) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

DreamTheater
Newbie
Posts: 19
Joined: Mon Oct 14, 2019 6:23 am

Re: Best way to avoid an error if an Internet Explorer Element is not found

Post by DreamTheater » Wed Dec 18, 2019 4:47 am

I use the following in some of my scripts:

Code: Select all

//Login loop
Let>PageReadyCounter=0
Label>CheckPageReady
Let>IGNOREERRORS=1
IEGetTagsByAttrib>{"https://URL"},A,innertext=Log in,T,PageReadyRes
Let>IGNOREERRORS=0

IfNot>PageReadyRes_1={"Log in"}
    Wait>0.5
    Let>PageReadyCounter=PageReadyCounter+1
    If>PageReadyCounter>120
        MDL>Login page was not loaded - shutting down.
        Goto>ShutDown
    EndIf>
    Goto>CheckPageReady
EndIf>
That one is fairly simple, it looks for a certain tag on the initial login page.
For that particular example there's no recovery (apart from the loop to retry every second or so) but depending on the situation you could tell it to refresh the page and try again, or look for other tags.

I guess the most important thing is Let>IGNOREERRORS=1 to prevent the popup error message for end users.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts