VBA interaction with Internet Explorer and use of getelementsbyclassname does not work

Asked

Viewed 67 times

0

I’ve been trying to create a code that makes me log into Internet Explorer(ie), go to yahoo’s website, add my stock search and search, but the search part won’t go.

This is my code:

linha_ticker = 2
ticker = Sheets("Ibovespa").Cells(linha_ticker, 3)

'variável com fórmula deve ser atribuida por meio do SET
Set ie = CreateObject("internetexplorer.application")
ie.navigate "https://br.financas.yahoo.com/"
ie.Visible = True

'ação para só prosseguir caso a página esteja completamente carregada
Do While ie.busy And ie.readystate <> "READYSTATE_COMPLETE"
    DoEvents
Loop

'procurar na pagina ie o input de valor 0 e colocar nele o que está na variável ativo
ie.document.getElementsByTagName("input")(0).Value = ticker
'clicar em buscar
ie.document.getElementsByClassName("Bgc($linkColor) Bgc($linkActiveColor):h Fz(s) Fw(500) H(35px) Py(0px) Px(15px) W(80px) Bdrstend(2px) Bdrsbend(2px) Ta(c)")(0).Click

And the html of the click button is this:

<button type="button" id="search-button" class="Bgc($linkColor) Bgc($linkActiveColor):h Fz(s) Fw(500) H(35px) Py(0px) Px(15px) W(80px) Bdrstend(2px) Bdrsbend(2px) Ta(c)" data-reactid="63">
<svg class="H(20px) W(20px) Va(m)! Fill(white)! Stk(white) Cur(p)" width="20" style="fill:#000;stroke:#000;stroke-width:0;vertical-align:bottom;" height="20" viewBox="0 0 24 24" data-icon="search" data-reactid="64">
<path d="M9 3C5.686 3 3 5.686 3 9c0 3.313 2.686 6 6 6s6-2.687 6-6c0-3.314-2.686-6-6-6m13.713 19.713c-.387.388-1.016.388-1.404 0l-7.404-7.404C12.55 16.364 10.85 17 9 17c-4.418 0-8-3.582-8-8 0-4.42 3.582-8 8-8s8 3.58 8 8c0 1.85-.634 3.55-1.69 4.905l7.403 7.404c.39.386.39 1.015 0 1.403" data-reactid="65">
</path>
</svg>
</button>

What might be going on?

Hug.

1 answer

0

You didn’t exactly pass the error behavior, which makes it a little difficult to analyze (for example, does it fill in Icker and then do nothing? Or he really makes a mistake?).

You can’t analyze the page either. You can have a iframe, which changes everything, as it is necessary to reference the iframe documents. You may have another object with that same class before, so the button would not be item 0 of the collection.

Anyway, no further information, considering that the button has an attribute ID, I would try to use another method to reference the button:

ie.document.getElementsById("search-button").Click

I hope it works.

Browser other questions tagged

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