vba: How to click on element within iframe - html

My goal is to click an element within a html Iframe, but nothing worked for me so far. Hope someone can advise how to approach this task correctly as I am running in circles for weeks now.
I have tried to click on a div Id, span title but nothing worked so far. I believe it is because a wrong syntex
Option Explicit
Sub it_will_work()
'make the app work faster?
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'--------------------------------
Dim sht As Worksheet
Set sht = ThisWorkbook.Sheets("Fields") 'my data will be stored here
Dim LastRow As Long
LastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row 'range definition
Dim i As Long 'Will be used for a loop that navigate to different url
For i = 2 To LastRow 'First url starts at row 2 untill the last row
Dim IE As Object 'Internet Explorer declaration
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.navigate sht.Range("A" & i).Value 'My url that I want to navigate to
While IE.readyState <> 4 Or IE.Busy: DoEvents: Wend
Dim Doc As New HTMLDocument 'Will be used for the main html page
Set Doc = IE.document
Doc.getElementById("tab7").Click 'data taht need to be updated is here
'Global workgroup data that will effect the workgroup data(dependency)
Doc.getElementById("mcdResourceGlobalWorkgroup_ddltxt").Value = sht.Range("W" & i).Value
Doc.getElementById("mcdResourceGlobalWorkgroup_ddltxt").Focus
Doc.getElementById("mcdResourceGlobalWorkgroup_ddlimg").Click
'Workgroup dropdown, that need to be choosen within the Iframe:
Doc.getElementById("ResourceWorkgroup").Value = sht.Range("X" & i).Value '1) worgroup that I want to insert
Doc.getElementById("ResourceWorkgroup").Focus
Doc.getElementById("_IB_imgResourceWorkgroup").Click '2) Cliking here will generate dropdown values according the value inserted above
Application.Wait Now + TimeValue("00:00:5") 'before refering to Iframe I let the values to be loaded
'***from this point I have the issue where I try to access Iframe and click on the desired element:***
'Here I declare Iframe
Dim objIFRAME As Object
Set objIFRAME = IE.document.getElementsByTagName("iframe")
Debug.Print TypeName(objIFRAME)
'Here I ask to click on a title within the Iframe where value = X
objIFRAME.getElementsByName("title").Value = sht.Range("X" & i).Value.Click
Next i
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
After the url loads the following steps should happen:
Click on tab 7 -> this will open the correct tab to work on
inseart value from clumn "W" to "Global workgroup" field
focus on "Global workgroup" field
Click on an image that validate the "Global workgroup" field
(validates the instered value)
inseart value from clumn "X" to "Workgroup" field
focus on "Workgroup" field
Click on image that opens the drop down options, which is generated
according the inserted value to "Workgroup" field
Within the Iframe, Click on the title that is equal to value
which was inserted to "Workgroup" field
I have also tried to use Selenium IDE so I can see how the recorded macro access the Iframe and click the desired elemnt:
Command: Select frame | Target: Index=2
Click | Target: css=span[title="APAC"]
I have tried to mimic the stpes above in VBE, but couldn't find a way to write it properly. I event tried to download & apply selenium driver and run the code using the selenium library but got stuck as well.
Below image is the html code of the Iframe and the desired element I want to click on:

You should be able to use the following syntax
ie.document.querySelector("[id='_CPDDWRCC_ifr']").contentDocument.querySelector("span[title=APAC]").click
With selenium you can use
driver.SwitchToFrame driver.FindElementByCss("[id='_CPDDWRCC_ifr']")
driver.FindElementByCss("span[title=APAC]").click
With your existing tag solution you need to use an index. For example,
objIFRAME(0)
Then querySelector on the contentDocument of that.

Related

Excel VBA macro to get HTML SPAN ID value

I appreciate there are similar questions, but as a novice I find it hard to full adapt examples.
Problem Statement
I want the create a macro in Excel to pull the "last updated" value found on the website https://www.centralbank.ae/en/fx-rates. Specifically this is found within their HTML code (value example also below):
<span class="dir-ltr">11 Feb 2021 6:00PM</span>
What I wanted to Repurpose
The code here (https://www.encodedna.com/excel/extract-contents-from-html-element-of-a-webpage-in-excel-using-vba.htm) seemed to be a very clean way of launching IE in the background and then clearing down all elements thereafter. It iterates through hyperlinks which I don't need to do.
My code doesn't seem to work:
Option Explicit
Const sSiteName = "https://www.centralbank.ae/en/fx-rates"
Private Sub GetHTMLContents()
' Create Internet Explorer object.
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = False ' Keep this hidden.
IE.navigate sSiteName
' Wait till IE is fully loaded.
While IE.readyState <> 4
DoEvents
Wend
Dim oHDoc As HTMLDocument ' Create document object.
Set oHDoc = IE.document
Dim oHEle As HTMLSpanElement ' Create HTML element (<span>) object.
Set oHEle = oHDoc.getElementById("dir-ltr").innerText ' Get the element ref using its ID. [A]
' Clean up.
IE.Quit
Set IE = Nothing
Set oHEle = Nothing
Set oHDoc = Nothing
End Sub
Once it works printing to innerText, I thought you can replace line commented by [A] with something like this but again not 100% sure how to replace:
Cells(iCnt + 1, 1) = .getElementsByTagName("h1").Item(iCnt).getElementsByTagName("a").Item(0).innerHTML
The goal is to print this SPAN CLASS ID value into a cell in an Excel worksheet (say "Sheet1").
The span tag has no ID. dir-ltr is the class. You can get all elements with a specific class with getElementsByClassName(). With the get methods with the plural Elements you create a node collection which is based by index 0. The class dir-ltr is the one and only class with this name in the document.
You can refer to it via index 0 which will be written behind the name of the node collection (like an array) or behind the method call. If you do it after the method call the node collection will be destroyed imidiatly but you get the indexed element of the list.
If you want to read the innertext you can do it directly behind the index but than you have a string, no object. I used that in the following code:
Private Sub GetHTMLContents()
Const sSiteName = "https://www.centralbank.ae/en/fx-rates"
Dim IE As Object
'Create Internet Explorer object.
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = False ' Keep this hidden.
IE.navigate sSiteName
' Wait till IE is fully loaded.
While IE.readyState <> 4: DoEvents: Wend
'New sheet with name "New sheet" at the end
ThisWorkbook.Sheets.Add after:=Sheets(Worksheets.Count)
ThisWorkbook.ActiveSheet.Name = "New sheet"
' Get the element ref using its ID. [A]
ThisWorkbook.Sheets("New sheet").Cells(1, 1) = IE.document.getElementsByClassName("dir-ltr")(0).innerText
' Clean up.
IE.Quit
Set IE = Nothing
End Sub

VBA code to scrape data using html/javascript won't work

I want to make VBA code to search on a website on the basis of input made in the first column. Range is from A1 to A102. This code is working fine except one thing: It copies my data from Excel Cell and then paste it in the Search box of website. But it doesn't click the search button Automatically. I welcome any good Suggestions from Experts.
I know how to scrape data from websites but there is a specific class for this searchbox button. What would be this class I should use to made click? This question is relatable to both VBA and javascript/html Experts.
I am getting this as button ID " nav-search-submit-text " and this code as `Class " nav-search-submit-text nav-sprite ", when I click on Inspect element.
Both don't work?
Thanks
Private Sub worksheet_change(ByVal target As Range)
If Not Intersect(target, Range("A1:A102")) Is Nothing Then
Call getdata
End If
End Sub
Sub getdata()
Dim i As Long
Dim URL As String
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
Set IE = CreateObject("InternetExplorer.Application")
'Set IE.Visible = True to make IE visible, or False for IE to run in the background
IE.Visible = True
URL = "https://www.amazon.co.uk"
'Navigate to URL
IE.Navigate URL
'making sure the page is done loading
Do
DoEvents
Loop Until IE.ReadyState = 4
'attempting to search date based on date value in cell
IE.Document.getElementById("twotabsearchtextbox").Value = ActiveCell.Value
'Sheets("Sheet1").Range("A1:A102").Text
'Select the date picker box and press Enter to 'activate' the new date
IE.Document.getElementById("twotabsearchtextbox").Select
'clicking the search button
IE.Document.getElementsByClassName("nav-sprite").Click
'Call nextfunction
End Sub
To use web scraping with Excel, you must be able to use both VBA and HTML. Additionally CSS and at least some JS. Above all, you should be familiar with the DOM (Document Object Model). Only with VBA or only with HTML you will not get far.
It's a mystery to me why you want to do it in a complicated way when you can do it simply via the URL. For your solution you have to use the class nav-input. This class exists twice in the HTML document. The search button is the element with the second appearance of nav-input. Since the indices of a NodeCollection start at 0, you have to click the element with index 1.
Sub getdata()
Dim URL As String
Dim IE As Object
URL = "https://www.amazon.co.uk"
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True ' True to make IE visible, or False for IE to run in the background
IE.Navigate URL 'Navigate to URL
'making sure the page is done loading
Do: DoEvents: Loop Until IE.ReadyState = 4
'attempting to search date based on date value in cell
IE.Document.getElementById("twotabsearchtextbox").Value = ActiveCell.Value
'clicking the search button
IE.Document.getElementsByClassName("nav-input")(1).Click
End Sub
Edit: Solution to open offer with known ASIN
You can open an offer on Amazon webpage directly if you know the ASIN. To use the ASIN in the active cell in the URL (this does not work reliably. If you have to press Enter to finish the input, the active cell is the one under the desired one), it can be passed as a parameter to the Sub() getdata():
Private Sub worksheet_change(ByVal target As Range)
If Not Intersect(target, Range("A1:A102")) Is Nothing Then
Call getdata(ActiveCell.Value)
End If
End Sub
In the Sub() getdata() the URL with the transferred ASIN is then called:
Sub getdata(searchTerm As String)
Dim URL As String
Dim IE As Object
'Use the right base url
URL = "https://www.amazon.co.uk/dp/" & searchTerm
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True ' True to make IE visible, or False for IE to run in the background
IE.Navigate URL 'Navigate to URL
'making sure the page is done loading
Do: DoEvents: Loop Until IE.ReadyState = 4
End Sub
It's also possible to do that all in the worksheet_change event of the worksheet (Include getting price and offer title):
Private Sub worksheet_change(ByVal target As Range)
If Not Intersect(target, Range("A1:A102")) Is Nothing Then
With CreateObject("InternetExplorer.Application")
.Visible = True ' True to make IE visible, or False for IE to run in the background
.Navigate "https://www.amazon.co.uk/dp/" & ActiveCell 'Navigate to URL
'making sure the page is done loading
Do: DoEvents: Loop Until .ReadyState = 4
'Get Price
ActiveCell.Offset(0, 1).Value = .document.getElementByID("priceblock_ourprice").innertext
'Get offer title
ActiveCell.Offset(0, 2).Value = .document.getElementByID("productTitle").innertext
End With
End If
End Sub

VBA Web search button - GetElementsbyClassName

I have a problem with the VBA code.
I would like to open this website: https://www.tnt.com/express/en_us/site/tracking.html and in Shipment numbers search box I would like to put active cells from Excel file. At the beginning I tried to put only a specific text for example: "777777".
I wrote the below code but unfortunately, the search button is empty and there is no error. I tried everything and I have no idea what should I change in my code.
Any clues? Thank you in advance.
HTML:
<input class="__c-form-field__text ng-touched ng-dirty ng-invalid" formcontrolname="query" pbconvertnewlinestocommasonpaste="" pbsearchhistorynavigation="" shamselectalltextonfocus="" type="search">
VBA:
Sub TNT2_tracker()
Dim objIE As InternetExplorer
Dim aEle As HTMLLinkElement
Dim y As Integer
Dim result As String
Set objIE = New InternetExplorer
objIE.Visible = True
objIE.navigate "https://www.tnt.com/express/en_us/site/tracking.html"
Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop
Dim webpageelement As Object
For Each webpageelement In objIE.document.getElementsByClassName("input")
If webpageelement.Class = "__c-form-field__text ng-pristine ng-invalid ng-touched" Then
webpageelement.Value = "777"
End If
Next webpageelement
End Sub
You could use the querySelector + class name to find an element.
something like
'Find the input box
objIE.document.querySelector("input.__c-form-field__text").value = "test"
'Find the search button and do a click
objIE.document.querySelector("button.__c-btn").Click
No need to loop through elements. Unless the site allows you to search multiple tracking numbers at the same time.
It seems automating this page is a litte tricky. If you change the value of the input field it doesn' t work. Nothing happen by clicking the submit button.
A look in the dom inspector shows several events for the input field. I checked them out and it seems we need to paste the value over the clipboard by trigger the paste event of the shipping field.
In order for this to work without Internet Explorer prompting, its security settings for the Internet zone must be set to allow pasting from the clipboard. I'm using a German version of IE, so I have problems explaining how to find the setting.
This macro works for me:
Sub TNT2_tracker()
Dim browser As Object
Dim url As String
Dim nodeDivWithInputField As Object
Dim nodeInputShipmentNumber As Object
Dim textToClipboard As Object
'Dataobject by late binding to use the clipboard
Set textToClipboard = CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
url = "https://www.tnt.com/express/en_us/site/tracking.html"
'Initialize Internet Explorer, set visibility,
'call URL and wait until page is fully loaded
Set browser = CreateObject("internetexplorer.application")
browser.Visible = True
browser.navigate url
Do Until browser.ReadyState = 4: DoEvents: Loop
'Manual break for loading the page complitly
'Application.Wait (Now + TimeSerial(pause_hours, pause_minutes, pause_seconds))
Application.Wait (Now + TimeSerial(0, 0, 3))
'Get div element with input field for shipment number
Set nodeDivWithInputField = browser.Document.getElementsByClassName("pb-search-form-input-group")(0)
If Not nodeDivWithInputField Is Nothing Then
'If we got the div element ...
'First child element is the input field
Set nodeInputShipmentNumber = nodeDivWithInputField.FirstChild
'Put shipment number to clipboard
textToClipboard.setText "7777777"
textToClipboard.PutInClipboard
'Insert value by trigger paste event of the input field
Call TriggerEvent(browser.Document, nodeInputShipmentNumber, "paste")
'Click button
browser.Document.getElementsByClassName("__c-btn")(0).Click
Else
MsgBox "No input field for shipment number found."
End If
End Sub
And this function to trigger a html event:
Private Sub TriggerEvent(htmlDocument As Object, htmlElementWithEvent As Object, eventType As String)
Dim theEvent As Object
htmlElementWithEvent.Focus
Set theEvent = htmlDocument.createEvent("HTMLEvents")
theEvent.initEvent eventType, True, False
htmlElementWithEvent.dispatchEvent theEvent
End Sub
As #Stavros Jon alludes to..... there is a browserless way using xhr GET request via API. It returns json and thus you ideally need to use a json parser to handle the response.
I use jsonconverter.bas as the json parser to handle the response. Download raw code from here and add to standard module called JsonConverter . You then need to go VBE > Tools > References > Add reference to Microsoft Scripting Runtime. Remove the top Attribute line from the copied code.
Example request with dummy tracking number (deliberately passed as string):
Option Explicit
Public Sub TntTracking()
Dim json As Object, ws As Worksheet, trackingNumber As String
trackingNumber = "1234567" 'test input value. Currently this is not a valid input but is for demo.
Set ws = ThisWorkbook.Worksheets("Sheet1") 'for later use if writing something specific out
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", "https://www.tnt.com/api/v3/shipment?con=" & trackingNumber & "&searchType=CON&locale=en_US&channel=OPENTRACK", False
.send
Set json = JsonConverter.ParseJson(.responseText)
End With
'do something with results
Debug.Print json("tracker.output")("notFound").Count > 0
Debug.Print JsonConverter.ConvertToJson(json("tracker.output")("notFound"))
End Sub

Access VBA code to extract google map result from AA mileage calculator website

I am trying to use vba (Access 2013) to automate a route finder website (https://www.theaa.com/driving/mileage-calculator.jsp)
I have some working code that on a form command button allows me to:
1. open an external instance of internet explorer (as opposed to a browser control)
2. enter postcode/address information from my db
3. click a link that adds further destination fields if required
4. change cost per mile default from a text box on my form
5. click a button called "Get Route"
When "Get Route" is clicked this produces a page with the results of the search, which include a static google map with the route steps marked on a purple line A B C etc. I want to capture this image and use in my db form using a webbrowser or image field control so I can use it in a report when I have conducted searches for the most economical route.
I have looked at the DOM Explorer and source code but I can't work out how to do this or if it is possible? There is a div "gmnoprint" that is highlighted when the map is selected and in the source code there is a reference to "mapContainer" which seems to be in the right area of the sequence of actions/results.
I don't know how to drill through the references and create code which will allow me to put the map in my form. The selection of code I have posted is one part of a select case which determines what can be entered into my text boxes, the GoogleMap image code would presumably go where indicated?
I would say I am an enthusistic learner and a moderate user without any formal training. I would very much appreciate any replies.
Dim IE As New InternetExplorer
Dim doc As HTMLDocument
Dim RDate As String
On Error GoTo Errorhandler
RDate = Me.TxtRouteDate
'................................................................
Select Case Me.TxtNoSum
Case Is = IsNull(Me.TxtPC1) Or IsNull(Me.TxtPC2)
MsgBox "Please Enter at least 2 Postcodes"
Case Is <= 2
MsgBox "Please Enter at least 2 Postcodes"
Case Is = 3
IE.Visible = True
IE.Navigate "https://www.theaa.com/driving/mileage-calculator.jsp"
IE.Top = 20
IE.Left = 50
IE.Height = 1300
IE.Width = CInt(Int((1000 * Rnd()) + 1))
While IE.Busy
DoEvents
Wend
Set doc = IE.Document
With doc
'Clears previous searches
doc.all("mcDeleteRoutesLink").Click
'Inserts info into web site text boxes.
doc.getElementById("RouteDate").Value = RDate
doc.getElementById("RouteFrom").Value = Me.TxtPC1
doc.getElementById("RouteTo").Value = Me.TxtPC2
doc.getElementById("fuelPricePerLitre").Value = Me.TxtPPL
End With
While IE.Busy
DoEvents
Wend
'Clicks "Get Route" Button
Dim btn As Object
Set btn = doc.getElementById("getRouteWrapper").Children(0)
If Not btn Is Nothing Then
btn.Click
While IE.Busy
DoEvents
Wend
' Inserts distance recorded by AA mileage calculator into text control on my form
Set htmlDist = doc.all("routeDistanceTotal")
If Not htmlDist Is Nothing Then
Me.TxtDistance = htmlDist.innerText
'Google image code to go here after map page loads?
End If
End If
(Next Case)

Problems Using VBA to Submit a Web Page - Using the click button function but web page won't submit

I am writing a VBA code to pull data from a website (https://app.buzzsumo.com/top-content). I have a functional code that runs without errors however I still can't get the webpage to actually submit the form when the click command runs. I have tried many different approaches and combinations of submitting the form/clicking the submit button but none have seemed to work so far. Below is my current code.
Sub clickFormButton()
Dim ie As Object
Dim form As Variant,
Dim button As Variant
'add the “Microsoft Internet Controls” reference in VBA Project
Set ie = CreateObject("InternetExplorer.Application")
'using input box to enter URL I am serching for
Search_URL = InputBox("Enter URL to Search For")
With ie
.Visible = True
.navigate ("https://app.buzzsumo.com/#/top-content")
'Ensure that the web page downloads completely
While ie.ReadyState <> 4
DoEvents
Wend
'assigning the input variables to the html elements of the form
ie.document.getElementsByName("q").Item.innertext = Search_URL
'finding and clicking the button
Set objInputs = ie.document.getElementsByTagName("input")
For Each ele In objInputs
If ele.Title Like "Press Enter to Search" Then
ele.Click
End If
End With
End Sub
I have also tried other methods to find and click the button such as:
'Dim i As Variant
'Set form = ie.document.getElementsByClassName("btn btn-highlight")
'For i = 1 To 5
'If form.Item(i).DefaultValue = "Search!" Then
'Set button = form.Item(i)
'button.Click
'End If
'Next i
Please provide any recomendations on what I may be missing or how I can get this code to actually submit the form and advance to the search results. Thanks in advance for any help you can provide!
Here are some additional details: Unfortunately the element I am trying to click (the "Search" button) does not have an ID or Name associated with it. This is why is was trying alternative approaches, such as looping through all of the object and trying to find the one with the right “Title”. Here is the code for the element from the DOM explorer:
<input title="Press Enter to search" class="btn btn-highlight" type="submit" ng-disabled="topContentSearchForm.$invalid" value="Search!"/>
The only attributes associated with it are:
class: btn btn-highlight
type: submit
ng-disabled: topContentSearchForm.$invalid
value: Search!
title: Press Enter to Search
Please let me know if there is another way to find the element ID/name? or if there is another way to click the button without these attributes? Thanks
I know this is an old post but... I have been using this effectively..
'click login
Set htmlDoc = .document
Set htmlColl = htmlDoc.getElementsByTagName("input")
Do While htmlDoc.readyState <> "complete": DoEvents: Loop
For Each htmlInput In htmlColl
If Trim(htmlInput.Type) = "submit" Then
htmlInput.Click
Exit For
End If
Next htmlInput
A couple of ideas:
While ie.ReadyState <> 4
DoEvents
Wend
If you have javascripts on the page use Application.Wait Now + TimeSerial(0, 0, 4) (basically wait for 4 seconds) instead.
Second I don't understand why you need to loop through all the objects on the web page. The easier way would be to go that webpage in IE, hit F12 and select element in DOM explorer, you can get the ID or Name of the button and then use ie.document.GetElementByID("buttonID").Click or ie.document.GetElementsByName("buttonName").Item.Click
Let me know if this helps.
Edit: After inspecting the particular webpage it appears that the ID and Name attributes for that button are missing. So I had to resort to the following:
Dim i As integer
Set form = ie.document.getElementsByClassName("btn btn-highlight")
On Error Resume Next
For i = 1 To 20
If form.Item(i).DefaultValue = "Search!" Then
form.Item(i).Click
End If
Next i
The relevant button is clicked for the fourth item (I had to manually go through the loop because 3rd item navigated away from the page to a pricing page, so i had to go back). Anyway the full code is the following, please note that you will need to go through this exercise again if there were changes to the webpage
Sub clickFormButton()
Dim ie As Object
Dim form As Variant
Dim button As Variant
'add the “Microsoft Internet Controls” reference in VBA Project
Set ie = CreateObject("InternetExplorer.Application")
'using input box to enter URL I am serching for
Search_URL = InputBox("Enter URL to Search For")
With ie
.Visible = True
.navigate ("https://app.buzzsumo.com/#/top-content")
End With
'wait for page to load
Application.Wait Now + TimeSerial(0, 0, 5)
'assigning the input variables to the html elements of the form
ie.document.getElementsByName("q").Item.InnerText = Search_URL
'finding and clicking the button
ie.document.getElementsByClassName("btn btn-highlight").Item(4).Click
End Sub
It looks like you could potentially just build the string URL, for example if you put "abcd" in the search field, the resulting URL will be:
https://app.buzzsumo.com/top-content?result_type=total&type=articles&num_days=360&tfc=false&general_article&infographic&video&page=1&guest_post&giveaway&interview&links_sitewide=true&unique_domains=true&backlinks=false&q=abcd&offset=0
Note the bolded portion which is the search query.
So, and this is just a quick idea that may work as long as you're not trying to abuse their system by sending 1000's of automated requests:
Sub FetchWebsite()
Dim ie As Object
Dim form As Variant
Dim button As Variant
Dim url As String
'add the “Microsoft Internet Controls” reference in VBA Project
Set ie = CreateObject("InternetExplorer.Application")
'using input box to enter URL I am serching for
Search_URL = InputBox("Enter URL to Search For")
'### BUILD THE FULL URL
url = "https://app.buzzsumo.com/top-content?result_type=total&type=articles&num_days=360&tfc=false&general_article&infographic&video&page=1&guest_post&giveaway&interview&links_sitewide=true&unique_domains=true&backlinks=false&q=" & Search_URL & "&offset=0"
With ie
.Visible = True
.navigate url
End With
'wait for page to load
Do
Loop While Not ie.ReadyState = 4 And Not ie.Busy
AppActivate "Internet Explorer"
End Sub
I did some poking around in the Locals window and this should also work, modified from your code. This would be the Form.Submit that I mentioned in comment on OP.
Sub clickFormButton()
Dim ie As InternetExplorer
Dim form As Variant
Dim button As Variant
Dim ele As HTMLFormElement
'add the “Microsoft Internet Controls” reference in VBA Project
Set ie = CreateObject("InternetExplorer.Application")
'using input box to enter URL I am serching for
Search_URL = InputBox("Enter URL to Search For")
With ie
.Visible = True
.navigate ("https://app.buzzsumo.com/#/top-content")
End With
'wait for page to load
Do
Loop While Not ie.ReadyState = 4 And Not ie.Busy
'assigning the input variables to the html elements of the form
ie.document.getElementsByName("q").Item.InnerText = Search_URL
'finding and clicking the button
ie.document.getElementsByClassName("btn btn-highlight").Item(4).form.submit
End Sub
CSS selector:
You can use CSS selector of #search-btn > div. Which is div within className search-btn. "#" means class.
VBA:
Use .querySelector method to apply CSS selector:
ie.document.querySelector("#search-btn > div").Click