Manipulating Webpage Actions With VBA (via Selenium & Firefox Geckodriver)

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,608
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Does anyone here have experience with manipulating browser (Firefox) input via Excel VBA. Is it even possible?
I have been working on some test code that uses Selenium and Geckodriver to try and accomplish this. Looking to access a webpage, populate it's search field, and execuate the search.
I've accessed the Firefox prerequisistes. I have a valid version (v133) of Firefox, v0.35 of geckodriver, and I have installed Selenium 4.27.1 via Python. I originally installed the Selenium Basic, but realized it wasn't supported by geckodriver. I installed Python hoping that the Python based Selenium (?) would be what I needed. Not sure though now. The only difference I found in configuring everything, was there are no libraries to add to Excel references unlike the Basic vesion.

here is my code I'm experimenting with:
Rich (BB code):
Sub OpenWebsiteInFirefox()
    ' Declare Selenium variables
   Dim driver As New Selenium.WebDriver
    Dim searchBox As Object
    Dim geckopath As String
    Dim searchTerm As String
 
    geckopath = "C:\Operations\geckodriver.exe"
    searchTerm = "Historic Chess Masters"
  
    ' Start Firefox browser
    driver.Start "firefox", geckopath
   
    ' Navigate to the website (for example, Google)
    driver.Get "https://www.drinkwillibald.com/"
 
    ' Wait for the page to load (adjust the sleep time as needed)
    driver.Wait 2000
 
    ' Find the search box using its name or ID
    Set searchBox = driver.FindElementByName("q")
 
    ' Type in the search box
    searchBox.SendKeys "Excel VBA automation"
 
    ' Execute the search by pressing Enter
    searchBox.SendKeys Keys.Enter
 
    ' Wait for results to load (optional)
    driver.Wait 2000
End Sub

The line in red stops the code with an error: "User-defined type not defined

I had gotten closer with this code when I was using Selenium basic. It would open up a Firefox window, but would timeout on the line in purple. Error: "TimeoutErrorFirefox failed to open the listening port 127.0.0.1:12825 with 15s" (I didn't get the error associated with the red line).

Grateful to hear from others with experience with this concept of VBA based webpage manipulation in whatever method (if any) that works. I am prepared for this method not to work, but I hope there are other options if not.

I did cross post (more detailed) at the Selenium user support page, but it has been several days stuck in moderator approval. It hasn't been posted yet.
 
I think I've solved #2 issue. I declared driver as a public variable. (and removing the Dim in the procedure)
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
The wait method should leave the window open.
driver.wait 30000

It depends what you're waiting for, but I like to use:
VBA Code:
Do While True
    DoEvents
Loop
 
Upvote 0

Forum statistics

Threads
1,224,743
Messages
6,180,686
Members
452,994
Latest member
Janick

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top