'launching chrome or IE via selenium VBA
I have written a code for web data downloading using selenium VBA, it works good in Firefox, but many time Firefox is crashing. I tried to launch chrome/IE from vba but it's not properly happening. Below is my code....please help.
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
Error screenshot is as below:
How to launch chrome or IE ?
My chrome driver path is C:\Program Files (x86)\SeleniumWrapper\chromedriver.exe"
and ie driver path is C:\Program Files (x86)\SeleniumWrapper\IEDriverServer.exe"
Solution 1:[1]
@purnendumaity
I've been using Selenium Webdriver with VBA for a while. My feeling using it on Windows XP, 7 or 8 is, it only works well (and not very well) with Chrome. Selenium forum users have said that the most recent Firefox versions crashes with Selenium.
Well, Chrome works. Firefox crashes and IE..... (=
I've created a default macro to configure Chrome before open it. I believe that the trick is, always open a default url and then, go to your own:
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
And then:
Private selenium As New SeleniumWrapper.WebDriver
Public Sub MyCode()
Call ConfigureChrome
selenium.Open URL, 30000
'blabalbalbal
End Sub
I hope it helps
Solution 2:[2]
I know you need selenium.Get "/"
after launching chrome, so it may be the same with IE.
You've also declared selenium
as a web driver, but then used driver
in your code, so maybe try the below instead:
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
Solution 3:[3]
This simple trick to make open your URL in the chrome instead of data;
Sub test()
Dim selenium As New SeleniumWrapper.WebDriver
selenium.Start "chrome", "https://www.google.co.in"
selenium.Open ("https://www.google.co.in")
End Sub
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Tomamais |
Solution 2 | dhumphreys |
Solution 3 | Kathir vtv |