问题
Code is working well but after running several times it stuck with Run-time error '21'.
It cannot open webdriver with run-time error '21': as attached picture.
'bot. start "Chrome" which is the code that has the error.
Chrome version: 83.0.4103.97
Selenium: SeleniumBasic-2.0.9.0
enter image description here
Dim bot As New WebDriver
Dim ele As WebElement
Dim picEle As WebElement
Dim awbaLI As WebElements
Dim AWB As List
bot.Start "Chrome"
bot.Get "https://google.com"
回答1:
The error message says that you Port (62982, according to your provided screenshot) is still in use and thus cannot be reused.
You must also close to bot instance in order to release the port again (this also explains why it works again when you restart your PC (because then all the ports are released automatically)
In this case this can be done by calling bot.Quit
at the very end of your bot usage / script!
来源:https://stackoverflow.com/questions/64585947/run-time-error-21-vba-seleniumchrome