Vba interacting with IE

Asked

Viewed 152 times

-1

I need to click on an element of a website:

Código Html

The problem is that there are several of these and I made this code:

For Each obj In ie.Document.all
    obj.Click
Next

But this code clicks on all the objects of the page I can not only in the specific ojbetos?

There is no ie.Document.all that does the obj.click function only on the part that I want to click or a code that clicks only the objects that have in their class: "clickable" not to click all of the page.

  • Please do not insert code as image and which website?

2 answers

1

Good morning,

Try it like this:

For Each obj In ie.Document.all
    if obj.id = "img_684517_43_2506" then
        obj.Click
    end if
Next

0

If the objects you want to click are those of the class clicavel, just iterate using the method getElementsByClassName:

For Each obj In IE.Document.getElementsByClassName("clicavel")
    obj.Click
Next

If they are just a few objects of the clickable class, put a ifwithin the for, to click only the ones you want.

  • Dude, gave an error at runtime '438'; The object does not accept this property or method

  • Can you tell which line gives the error? obj.Click, whereas the script iterates all objects of the "clickable" class, can you take a look at which object is active when the error occurs? Probably, this object cannot receive the method .Click, or something like that.

  • in this line For Each obj In ie.Document.getElementsByClassName("clickable")

  • Maybe you are trying to assign an object of one type to a variable of another. All objects in the class clicavel on the SBE page are the same category? For example, if your variable obj is declared as HTMLimg and on the page there is an object INPUT with class clicavel, when his turn comes to iteration, the code will try to assign the object, which is INPUT, to a variable HTMLImg, and will give this error. The variable obj, how is it stated? Just in case, try to declare obj as variant, see if it solves. If it doesn’t, try iterating with a numeric counter.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.