Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
444 views
in Technique[技术] by (71.8m points)

Automation Error when running Selenium VBA on Excel 2019

I was running the following code without a problem on a machine with excel 2013. We recently upgraded to Excel 2019 and the macro now returns an Automation error. I noticed that the error seems to be in the driver.start section , it looks like it's not 'registering' the reference. I have reinstalled the Selenium add-in , re-pointed the reference, tried different browsers ( chrome, edge etc) but to no avail .

Dim driver As New WebDriver
Dim keyObj As Selenium.keys
Dim IE As Object

Set keyObj = New Selenium.keys

driver.Start "ie"
driver.Window.Maximize
driver.Get "https://www.google.com/"

Any suggestions/ ideas would be much appreciated.

question from:https://stackoverflow.com/questions/65918864/automation-error-when-running-selenium-vba-on-excel-2019

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

enter image description hereTry adding Selenium to references (Selenium Type Library).

It solved the error for me.

When you installed Selenium you checked the drivers? enter image description here

If you are using Chrome, have you downloaded the same version of chrome driver as your chrome browser version?

First of all, go to control panel and uninstall previous installation of selenium and then follow the steps 1- Download the latest version of chrome and make sure of the version of Chrome from Help >> About Google Chrome. You would see something like that Version 75.0.3770.142 (Official Build) (32-bit)

2- Download the latest version from the LINK

3- Download the chromedriver from the follwoing LINK Make sure of the version that suits your chrome version As for the Google Chrome version I posted the most suitable version of chromedriver is ChromeDriver 75.0.3770.140

Now setup SeleniumBasic >> After setup unzip the chromedriver file chromedriver_win32.zip and copy the chromedriver.exe to the path of selenium Here's two possibilties: First >> C:Program FilesSeleniumBasic Second >> C:Users%username%AppDataLocalSeleniumBasic Copy the chromedriver.exe to the SeleniumBasic path

Open new blank excel file >> Press Alt + F11 (Visual Basic Editor) >> Tools >> References >> Selenium Type Library

Insert new module and paste the following code to test

Sub Test()
    Dim sel As New WebDriver
    
    sel.Start "chrome", "https://www.google.com"
    sel.Get "/"
    Stop
End Sub

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...