Skip to content

Instantly share code, notes, and snippets.

@dck-jp dck-jp/sample.cls
Last active Mar 20, 2019

What would you like to do?
sample code of Selenium-VBA
Option Explicit
Private driver As SeleniumWrapper.WebDriver
Private Sub InitializeWebDriver()
Set driver = New SeleniumWrapper.WebDriver
Call driver.Start("firefox", "")
End sub
Private Sub Login()
driver.get ("/Default.aspx")
driver.findElementById("LoginId_TBox").SendKeys "username"
driver.findElementById("Pass_TBox").SendKeys "pass"
End Sub
Private Sub Search(ourRef As String)
Call driver.get("/Search.aspx")
Call driver.findElementById("MainContent_Ref_TBox").Clear
Call driver.findElementById("MainContent_Ref_TBox").SendKeys(ourRef)
Call driver.findElementById("MainContent_Search_Btn").Click
End Sub
Public Function GetText(ourRef As String)
Call InitializeWebDriver
Call Login
Call Search(ourRef)
Dim id: id = driver.findElementById("MainContent_OurRef_Link").getAttribute("href")
' 基本情報画面
Call driver.get("/OurRefInfo.aspx?id=" & id)
GetText = driver.findElementByCssSelector("#InfoContent_MainInfo > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2)").text
End Sub

This comment has been minimized.

Copy link

rashidkhan46211 commented Mar 13, 2016

Hi I am using code below why Chrome does not load my next page in new tab all the pages getting loaded in same (first tab) only.
Dim keys As New SeleniumWrapper.keys
Dim AllWin As SeleniumWrapper.WebElementCollection
selenium.Start "chrome", ""
selenium.setTimeout ("120000")
selenium.setImplicitWait (5000)

For intRowPosition = 1 to 5
selenium.selectWindow ("null")
selenium.Open ThisWorkbook.Sheets(HYPERLINK).Range("A" & intRowPosition)
selenium.switchToWindow selenium.WindowHandle
selenium.Wait 1000
selenium.SendKeys keys.Control & "t"
Next intRowPosition


This comment has been minimized.

Copy link

CatchColt commented Mar 13, 2016

Hi I'm hoping you can help. I've downloaded the latest version of selenium from Florent's github site.
I've tried running various sample code as test that its working but am having alot of trouble.

when i try your code:
Private Sub InitializeWebDriver()
Set driver = New SeleniumWrapper.WebDriver
Call driver.Start("firefox", "")
End Sub
I get a "user-defined type not defined".... I believe this is because I am not getting a SeleniumWrapper Type Library
in my VBA>Tools>Reference but rather just a Selenium Type Library

If I change the code to:
Private Sub myInitializeWebDriver()
Set driver = New selenium.WebDriver
driver.Start "firefox", ""
End Sub
The browser opens but immediately closes.

And finally if I add the line
To those lines, the browser opens and stays open but I get an "Object does not support this property or method"

I think maybe I've downloaded the wrong stuff but I've searched high and low and have no reason to believe its not the right file.

If you could point me in the right direction I would really appreciate it. Thank you


This comment has been minimized.

Copy link

NoviceDJ commented Jul 30, 2016

I am having the same problems as described by CatchColt above. I have also wondered which is the latest or best the SeleniumWrapper or SeleniumBasic and what is the difference (if any)
I also get a run-time error 6 (Overflow) when I use Microsoft Edge with webdriver. What can I do to stop these errors occurring?
Thank you fir reading this.


This comment has been minimized.

Copy link

ananthaganta commented Jul 9, 2017

I have noticed the same problem as CatchColt and NoviceDJ.
I am using Firefox 46 version. Any clues??


This comment has been minimized.

Copy link

daluu commented May 25, 2018

FYI, there is also an alternative to Selenium VBA, for those that might have issues with it:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.