I've created a script in vba using IE to click on a tab in a webpage. I would like to know how I can initiate a click on that tab using .execScript.
When I try like below, It works (not desirable approach):
Sub ExecuteScript()
Dim IE As New InternetExplorer, Html As HTMLDocument
With IE
.Visible = True
.navigate "https://stackoverflow.com/questions/tagged/web-scraping"
While .Busy Or .readyState < 4: DoEvents: Wend
Set Html = .document
Html.parentWindow.execScript "document.querySelector(""a[href='/questions/ask']"").click();"
End With
End Sub
The way I would like to do is the following so that I can use an object variable (adjacent or within) .execScript:
Set post = Html.querySelector("a[href='/questions/ask']")
Html.parentWindow.execScript "arguments[0].click();", post
But, it throws an error pointing at this line Html.parentWindow.execScript
Run-time error `429`
ActiveX component can't create object
How can I execute javascript within IE?