问题
I am om Windows 10. I am trying to use Selenium to automate the Edge browser (or any other browser) via Excel VBA.
I went to https://www.selenium.dev/downloads/
There I downloaded Selenium Server, Latest stable version 3.141.59 and Python 3.141.0 November 01, 2018 4.0.0a6.post1 May 28, 2020 Download (I am not using Python but I thought I might in the future.)
Then I opened Excel VBA and opened Tools but could not find the “Selenium Type Library” option in the drop down.
I did more reading and I downloaded SeleniumBasic at https://github.com/florentbr/SeleniumBasic/releases/tag/v2.0.9.0
This made the option “Selenium Type Library” appear on the Tools dropdown.
I selected the “Selenium Type Library” option.
I entered this code in the VBA editor, which I got off the web. It opens Chrome (could not find the syntax to open Edge).
Sub test2()
Dim driver As New WebDriver
Dim rowc, cc, columnC As Integer
driver.Start "Chrome"
Application.Wait Now + TimeValue("00:00:20")
End Sub
It failed. It bombed out on the line:
driver.Start "Chrome"
It gave an error: "Exception from unknown error"
I am totally lost on what to do. Help!
It would be greatly appreciated!
回答1:
Do you have the selenium chromium driver installed? That is required and it is different than the server and Visual library. This is the actual chrome binary that will launch and run. Download the latest version and place it in path such that basic can access it. I believe the path is C:\Users\ *Username\AppData\Local\SeleniumBasic
The executable should also be lowercase:
Dim driver As New WebDriver
driver.Start "chrome"
driver.Get "https://duckduckgo.com"
来源:https://stackoverflow.com/questions/62205408/excel-vba-using-selenium