Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Trying to detect non-existent elements in VBA

46 views
Skip to first unread message

McDudeson

unread,
Nov 22, 2019, 5:43:02 AM11/22/19
to Twebst
Hi there,

I know I'm late to this party. I really like the software and it looks perfect for my needs. I'm hoping some support might still be available.

I'm trying to automate an IE button click using Open Twebst through VBA in Microsoft Access, which works absolutely fine if the button exists. If the button doesn't exist, VBA throws an error. My attempts to detect whether or not the button exists before trying to click it, also throw an error.

Here is the code I'm using (which I got from the macro recorder:)

    Dim core As ICore
    Set core = New OpenTwebstLib.core

    Dim browser As IBrowser

    Set browser = core.StartBrowser("http://www.example.com/")

    Call browser.FindElement("input button", "id=EXAMPLE").Click

This works totally fine as long as the button exists.
But if it cannot be found, I get error 91 "Object variable or with block variable not set."

I read in the documentation for FindElement that if Core.loadTimeoutIsError = False, then it should be possible for FindElement to return a null value.

But I cannot even find any way to read the value of FindElement.

Debug.print
browser.FindElement("input button", "id=EXAMPLE") returns the same error 91.

Any ideas on what I might be doing wrong? If it's possible to post up an example of how to simply check if an element exists in VBA code, that would be extremely useful.

Many thanks in advance.

Reply all
Reply to author
Forward
0 new messages