我写了一个使用selenium VBA下载web数据的代码,它在Firefox中工作得很好,但很多时候Firefox会崩溃。我试图从vba启动chrome/IE,但它不能正常运行。下面是我的code....please帮助。
Public Sub Untitled_2()
Dim selenium As New SeleniumWrapper.WebDriver
Dim By As New By, Assert As New Assert, Verify As New Verify, Waiter As New Waiter
driver.start "firefox", "https://indexes.nasdaqomx.com/Account/LogOn"
'below 2 line don't work
driver.start "ie", "https://indexes.nasdaqomx.com/Account/LogOn"
driver.start "chrome", "https://indexes.nasdaqomx.com/Account/LogOn"
selenium.setImplicitWait 10000
selenium.Type "css=fieldset > div.editor-field > #UserName", "xxxxxxx"
selenium.Type "css=fieldset > div.editor-field > #Password", "xxxxxxx"
selenium.clickAndWait "css=fieldset > p > input.button.submit"
selenium.Click "id=menu-5"
selenium.Click "id=menu-1"
selenium.clickAndWait "link=U.S."
selenium.clickAndWait "id=NDX"
selenium.clickAndWait "link=Weighting"
selenium.Click "id=tradeDate"
selenium.Click "link=20"
selenium.Select "id=timeOfDay", "label=End of Day"
selenium.Click "id=update"
selenium.clickAndWait "id=exportLink"
selenium.Stop
End Sub错误截图如下:

如何启动chrome或IE?
我的chrome驱动程序路径是C:\Program Files (x86)\SeleniumWrapper\chromedriver.exe“
ie驱动程序路径为C:\Program Files (x86)\SeleniumWrapper\IEDriverServer.exe“
发布于 2015-10-01 05:09:04
@purnendumaity
我在VBA中使用Selenium Webdriver已经有一段时间了。我在Windows XP、7或8上使用它的感觉是,它只能在Chrome上运行得很好(而且不是很好)。Selenium论坛用户表示,最新的Firefox版本与Selenium一起崩溃。
好吧,Chrome是有效的。Firefox崩溃和IE.....(=
我创建了一个默认宏,用于在打开Chrome之前对其进行配置。我相信诀窍是,总是打开一个默认的url,然后转到你自己的:
Private Sub ConfigureChrome()
'initiate maximazed
selenium.addArgument "--start-maximized"
selenium.setPreference "download.default_directory", Replace(ThisWorkbook.FullName, ThisWorkbook.name, "")
selenium.setPreference "download.directory_upgrade", True
selenium.setPreference "download.extensions_to_open", ""
selenium.setPreference "download.prompt_for_download", False
selenium.setPreference "--disable-popup-blocking", ""
selenium.setPreference "--enable-panels", ""
selenium.Start "chrome", "http://google.com"
End Sub然后:
Private selenium As New SeleniumWrapper.WebDriver
Public Sub MyCode()
Call ConfigureChrome
selenium.Open URL, 30000
'blabalbalbal
End Sub我希望它能帮上忙
发布于 2019-12-04 01:43:54
我知道在启动chrome之后你需要selenium.Get "/",所以IE可能也一样。您还将selenium声明为web驱动程序,但随后在代码中使用了driver,因此可以尝试以下代码:
Public Sub Untitled_2()
Dim selenium As New SeleniumWrapper.WebDriver
Dim By As New By, Assert As New Assert, Verify As New Verify, Waiter As New Waiter
'below 2 line don't work
selenium.Start "ie", "https://indexes.nasdaqomx.com/Account/LogOn"
selenium.Get "/"
selenium.Start "chrome", "https://indexes.nasdaqomx.com/Account/LogOn"
selenium.Get "/"
selenium.setImplicitWait 10000
selenium.Type "css=fieldset > div.editor-field > #UserName", "xxxxxxx"
selenium.Type "css=fieldset > div.editor-field > #Password", "xxxxxxx"
selenium.clickAndWait "css=fieldset > p > input.button.submit"
selenium.Click "id=menu-5"
selenium.Click "id=menu-1"
selenium.clickAndWait "link=U.S."
selenium.clickAndWait "id=NDX"
selenium.clickAndWait "link=Weighting"
selenium.Click "id=tradeDate"
selenium.Click "link=20"
selenium.Select "id=timeOfDay", "label=End of Day"
selenium.Click "id=update"
selenium.clickAndWait "id=exportLink"
selenium.Stop
End Sub发布于 2016-01-30 22:03:06
这是一个简单的技巧,让你在chrome中打开你的URL而不是数据;
Sub test()
Dim selenium As New SeleniumWrapper.WebDriver
selenium.Start "chrome", "https://www.google.co.in"
selenium.Open ("https://www.google.co.in")
End Subhttps://stackoverflow.com/questions/32157107
复制相似问题