Browser automation in Excel VBA using Selenium

When it comes to browser automation tasks in Excel VBA like filling a web form, login to a website etc. most of them use Internet explorer by adding a reference to Microsoft Internet controls.

VBA users have been using IE automation from many years and most of them still use it. but there is a problem with Internet explorer! As we all know Internet explorer is the ‘God of all browsers’ – I mean we just use it to download other browsers because of its performance issues. Due to its poor performance automation also would be slow.


Then why not use high performance browsers like chrome or firefox? Yes this post is all about browser automation in VBA using selenium VBA wrapper which enables automating high performance browsers like chrome and firefox with just few lines of code.

What is Selenium

Selenium is a testing framework. Selenium automates browsers. That’s it! What you do with that power is entirely up to you. Primarily, it is for automating web applications for testing purposes, but is certainly not limited to just that. Boring web-based administration tasks can (and should!) also be automated as well.
Some good guy has written a .net wrapper for selenium which can be used in VBA and and that is the wrapper we are going to use in this tutorial.

Prerequisites :

  1. Basic knowledge of VBA
  2. Microsoft Excel installed in windows OS – Selenium VBA wrapper is a windows COM library so it works only on windows.
  3. Selenium VBA wrapper library – you can download and install it from here

Getting started with selenium VBA

1.Open any excel file, go to code editor (Alt + f11) and create a sub.

Public Sub seleniumtutorial()

End Sub

2.Add selenium VBA reference
go to tools > references > check ‘Selenium Type Library’ and click ok.

3.Define and start web driver
selenium web driver is what controls the browser.
syntax : Dim drivername as new WebDriver

 Dim bot as new WebDriver 

This driver is used to start and automate the browser.

4.Start browser
A browser can be started by using start method of webdriver.
syntax : driver.Start "browsername", "baseurl"
currently supports chrome, firefox, opera, PhantomJS & IE

bot.Start "chrome", ""

Simple example

Lets say we have to open a website and take screenshot of it. This can be done in just 2 lines of code. open website using Get method and screenshot using TakeScreenshot method

Public Sub seleniumtutorial()
Dim bot As New WebDriver
bot.Start "chrome", ""
bot.Get "/"
bot.TakeScreenshot.SaveAs (ActiveWorkbook.Path + "/screenshot.jpg")
'quit method for closing browser instance.
End Sub

Above code is self explanatory, when you run this code a screenshot of website is saved in the folder in which current excel file is present.
Too easy right! But who wants a screenshot of google? Ah yes, this simple example is used just to explain the steps in automation. I’ll be explaining few practical situations of automation later in this tutorial.

Adding more functionality

Lets say I’m an SEO analyst, I want to search few words on google and take screenshot of results. List of keywords are in column A of keywords sheet.


Lets start by adding a sub

Public Sub keywordsearch()

End Sub

1.Define WebDriver and a Range to get range of keywords.

Dim bot As New WebDriver, rng As Range

2.set range to list of cells in column A

Set rng = Range(Worksheets("keywords").Range("A2"), Worksheets("keywords").Range("A2").End(xlDown))

Above code makes setting a range dynamic because of End(xlDown)
End(xlDown) = next non empty cell in that row (the cell you reach when you press ctrl + down in excel)

3.Start web driver

bot.Start "chrome", ""

4.Loop through each cell in range, search keyword in google

For Each cell In rng
bot.Get "/"
bot.FindElementByName("q").SendKeys (cell.Value)
bot.Wait 1000
bot.TakeScreenshot.SaveAs (ActiveWorkbook.Path + "/screenshot_" + cell.Value + ".jpg")

In the above code, First we use For to loop through each cell then get ‘/’ which is homepage, if we need image search then ‘/images’ is used. After loading homepage, find input textbox to enter the search word.

Selenium has many methods to find a html element, Most commonly used methods to find elements are FindElementById, FindElementByName, FindElementByXpath

To find a HTML element, we need a selector. selector may be ID or name or Xpath or class or tag. If we have ID then FindElementById is used, FindElementByName is used if we have name of the element and so on. Finding a selector is simple, just go that webpage > right click on the element for which we need a selector > Inspect element. Prefer ID first, if there is no ID or name then copy xpath by right clicking again on the element.


As you can see in the image above, input textbox on google homepage has name attribute so we can use FindElementByName to find element and SendKeys method to type the keyword in textbox.

Button also has a name attribute with value “btnG” so FindElementByName is used again to find the search button and click it using Click method.

Wait for 1 second for search to complete and then take a screenshot using TakeScreenshot method , moving to next cell and finally quit driver using Quit method.

Noteworthy methods :

  1. All FindElement methods
  2. ExecuteScript – used to run any custom Javascript code.
  3. IsElementPresent (Removed now)
  4. PageSource
  5. refresh
  6. until
  7. Proxy
  8. Window

These are the commonly used methods in selenium, give it a try.

Wait for element in Selenium VBA

In previous versions of Selenium wrapper, There were few methods like IsElementPresent and WaitForElementPresent which were used to check if element is present, wait till element is available. But these methods are removed now. So How do we wait for elements?

Current methods which are used to identify elements such as FindElementById, FindElementByXPath have an implicit wait of 3 seconds which means – If the element was not found initially then these methods wait for up to 3 seconds to see element becomes available.

If you just want to wait till element becomes available then just increase the implicit wait time of these methods using :

driver.FindElementById("someId", timeout:=10000) 'waits for up to 10 seconds
driver.FindElementById("someId", timeout:=20000) 'waits for up to 20 seconds

Check is element is present in Selenium VBA

If your goal is to just check if element is present or not instead of waiting for the element then it can be done using :

Set myelement = bot.FindElementById("someId", timeout:=0, Raise:=False)
If myelement Is Nothing Then
MsgBox ("no element found")
End If

My Practical use cases of selenium VBA

I had an excel list in my office which contains usernames and passwords of around 200 clients which are used to login to a web admin panel. whenever I need some information, I had to login manually by copying the username & password of that particular client and pasting in the browser and login. So I just wrote some code for autologin, used a shortcut key for that sub. whenever I wanted to login, I just click on the client name and used my shortcut key!

Fetching youtube channel subscribers count. This can be done using XML HTTP requests also. comment below if you want to know more about fetching data using XML HTTP.

Automating product purchases, few other automations which need browser involvement exclusively.

Update : Checkout next part of this tutorial Scrape website using Selenium VBA to learn how to scrape website data using selenium VBA and best practises of scraping data in excel.

Wrapping up

This was a quick tutorial, there is lot more that can be done with selenium VBA. you can download official examples file here which contains lot of examples on Selenium VBA automations. have a look at them and start automating!

If you have any questions or feedback, please comment below.

Author: Ranjith kumar

A CA student by education, self taught coder by passion, loves to explore new technologies and believes in learn by doing.

111 Thoughts

  1. Hi Ranjith,
    I was using IE for browser automation.
    Can you help me doing a little conversion of my IE code for selenium so it clears me.
    Is it possible I can send you an excel file via email with code?
    Many thanks for your help


  2. Nice article, well described. I have been searching the web for an info closely related to this. I want to use to design a nice GUI of which the back end is to automate some mundane website tasks, seeing that it is possible to use selenium with VBA, I believe it should be possible to do with also, do you have an idea how I can go about this? Thanks in advance.

    1. Hello Mukhtar,

      Yes that can be done, Previously I have made few bots in using selenium. Best way to get started is using nuget package available here :

      If you are not familiar with using package manager then download Selenium web driver for .Net here :

      You can find it under C# language which is the same for too. Then add a reference to webdriver.dll and Import appropriate NameSpaces you need like
      Imports OpenQA.Selenium.Firefox
      Imports OpenQA.Selenium.Chrome

      By default, only firefox works without any additional driver. For chrome and other browsers you have to download appropriate drivers from the same link above. Hope that helps.

      1. Thanks Ranjith,

        I have realised where I was getting it wrong from your response. I didn’t find selenium download for before not knowing the same one for C# can be used for

  3. How to get the output in excel file. Code:
    Public Sub search()
    Dim bot As New WebDriver, rng As Range
    Set rng = Range(Worksheets(“keywords”).Range(“A2”), Worksheets(“keywords”).Range(“A2”).End(xlDown))
    bot.Start “chrome”, “”
    For Each Cell In rng
    bot.Get “/”
    bot.FindElementByName(“txt_Epicno”).SendKeys (Cell.Value)
    bot.Wait 5000
    End Sub
    I need your help.

      1. I need to get the details from the tamilnadu election website by clicking searchvoters and entering the voters epicno for ex : MSS3007457 it gives the all details of voters id . i need to save the details in excel format.all i need is the name,part no , slno and the voters constituency. I’ve voters epic number for checking in excel and i can only see the details in screen by running the macro which i learned from your site. The direct link is
        “”. can you help me in this regard.

        1. Hi, here’s code for scraping data of one voter :

          Public Sub scrapevoters()
          Dim bot As New WebDriver
          bot.Start “chrome”, “”
          bot.Get “/searchbyname.aspx”
          bot.FindElementById(“txt_Epicno”).SendKeys (“MSS3007457”)
          Sheets(1).Cells(1, 1).Value = bot.FindElementById(“lbnameen”).Text ‘Name
          Sheets(1).Cells(1, 2).Value = bot.FindElementById(“lbparten”).Text ‘Part number
          Sheets(1).Cells(1, 3).Value = bot.FindElementById(“lbserialen”).Text ‘Serial Number
          Sheets(1).Cells(1, 4).Value = bot.FindElementById(“lbpartnameen”).Text ‘Polling station
          End Sub

          Use it in a For loop to scrape multiple voters.
          bot.wait is not required here as it waits for page load automatically after click. Hope it helps.

          1. I’m able to loop through the following codes:
            Public Sub scrapevoters()
            Dim bot As New WebDriver, rng As Range, i As Integer
            Set rng = Range(Worksheets(“keywords”).Range(“A2”), Worksheets(“keywords”).Range(“A2”).End(xlDown))
            bot.Start “chrome”, “”
            For Each Cell In rng
            bot.Get “/”
            bot.FindElementByName(“txt_Epicno”).SendKeys (Cell.Value)
            i = i + 1
            Sheets(2).Cells(i, 2).Value = bot.FindElementById(“lbepicen”).Text
            Sheets(2).Cells(i, 3).Value = bot.FindElementById(“lbnameen”).Text
            Sheets(2).Cells(i, 4).Value = bot.FindElementById(“lbacnameen”).Text
            Sheets(2).Cells(i, 5).Value = bot.FindElementById(“lbparten”).Text
            Sheets(2).Cells(i, 6).Value = bot.FindElementById(“lbserialen”).Text
            Sheets(2).Cells(i, 7).Value = bot.FindElementById(“lbaden”).Text
            End Sub

            It works. Now here is the situation when the voters id is wrong then the page shows “Your Record is Not Available Now. For Further Enquiry Please Call 1950”. After the message looping stops. If the page doesnot display the records then it should go and fetch the next record. How to do it. sample voters list in my excel sheet BDZ2630614,BKH2950970,DDX2789360 and so on. the second record BKH2950970 gives “Your Record is Not Available Now. For Further Enquiry Please Call 1950”. how to loop through next record. Thanks

        2. Try this code
          Sub Test()
          Dim bot As New WebDriver
          Dim r As Long
          Dim c As Long

          bot.Start "chrome", ""
          bot.Get "/searchbyname.aspx"

          For r = 1 To Cells(Rows.Count, 1).End(xlUp).Row
          With Sheets(1)
          c = 1
          bot.FindElementById("txt_Epicno").SendKeys (CStr(.Cells(r, 1).Value))

              If bot.FindElementById("lblmsg").Text Like "Your Record is Not Available*" Then<br />
                  .Cells(r, c + 1).Value = "Your Record is Not Available Now. For Further Enquiry Please Call 1950."<br />
              Else<br />
                  .Cells(r, c + 1).Value = bot.FindElementById("lbnameen").Text<br />
                  .Cells(r, c + 2).Value = bot.FindElementById("lbparten").Text<br />
                  .Cells(r, c + 3).Value = bot.FindElementById("lbserialen").Text<br />
                  .Cells(r, c + 4).Value = bot.FindElementById("lbpartnameen").Text<br />
              End If<br />
          End With<br />

          Next r

          End Sub

      2. hi, selenium is opening browser but not navigating to url in vba, i read many articles and spent hours but nothing worked, will appreciate ur help

          1. Hi,

            it doesnt show any error, it simply opens chrome/firefox and
            that’s it , doesn’t do anything ahead

          2. I think you are just missing the http:// in URL. Are you using the same code as shown above?

          3. Hi , Ranjith thanks for your reply
            This is what is see in the url (data:,) when chrome opens,
            I tried your above code also
            Public Sub scrapevoters()
            Dim bot As New WebDriver
            bot.Start “chrome”, “”
            bot.Get “/searchbyname.aspx”
            end sub

            but again there is no navigation.
            Can you please share the link from where i can download selenium wrapper or selenium basic
            (let me tell you i am new to vba)

          4. Ranjith kumar, thanks for your replies, after a lot of tries i found that for me its only working when i downgrade firefox to version 39.0 , its fine anyways , its working all fine but firefox closes by itself after some seconds.

  4. Following codes inserted completes the looping:

    On Error Resume Next
    If Err.Number <> 0 Then
    Sheets(2).Cells(i, 2).Value = 0
    End If
    On Error GoTo 0
    But is there any other way to the solve the looping. Thanks

    1. Hi, The best way to handle this issue is to use IsElementPresent method on name element, check if element is present, then use goto next to continue loop if name element is not present.
      Name element would be present in every voter for sure and also rendered server side if epic number is found so using IsElementPresent method is the right way in this case but this method is buggy in the latest version of Selenium wrapper. So, Use the basic error handling that you mentioned above as a workaround for now. I would update you when IsElementPresent method is working fine.

  5. Hi,
    How to loop through select option and scrape data by each select options using selenium VBA .

  6. I ran the following and received this error. The Edge browser window opened but did not navigate to

    Public Sub seleniumtutorial()
    Dim bot As New WebDriver
    bot.Start “edge”, “”
    End Sub

    Error received: Run-time error ‘6’: NoSuchDriverError A session is either terminated or not started.

  7. Solved by updating the Edge driver:

    Copy “C:\Program Files (x86)\Microsoft Web Driver\MicrosoftWebDriver.exe”
    Rename it to edgedriver.exe
    Replace it in %LOCALAPPDATA%\SeleniumBasic

  8. Hi Ranjith, great article! I just found out about Selenium a few days ago and have been struggling to find an article with some well-explained examples of how to use Selenium. Do you mind if I email you about what I’m trying to accomplish using VBA and Selenium? I’m decent at VBA.

  9. I’m trying to use selenium to automate some work in Chrome. When I try to open chrome using the code below I get an error in chrome that says “You are using an unsupported command-line flag: –ignore-certificate-errors. Stability and security will suffer.”

    Sub OpenChrome()
    Dim selenium As New WebDriver
    selenium.Start “chrome”, “”
    selenium.setTimeout (“120000”)
    selenium.setImplicitWait (5000)
    End Sub

    I’ve built macros with VBA that automate work in internet explorer before, but I haven’t done it for chrome. It sounds like using selenium is the best way to build macros for navigating through chrome and interacting with the web. What am I doing wrong to get this error?

      1. Updated Selenium wrapper and now I’m getting this error:
        “Run-time error ’33’:

        session not created exception
        from unknown error: Runtime.executionContextCreated has invalid

        (Session info: chrome=54.0.2840.99)”

        Does this error look familiar?

        1. Okay, I tested it out with the latest version of selenium wrapper and got the same error. So I looked into the chrome driver version and found out that it’s v 2.21while the latest version with bug fixes for chrome 54 is v 2.25.

          Selenium wrapper installer comes with v 2.21 so we have to manually update the driver.

          First download chrome driver 2.25 from here – then go to your selenium path – C:\Users\username\AppData\Local\SeleniumBasic and replace the chrome driver with the latest one and it should work fine.

          I’ll make a request to update the chrome driver in selenium wrapper installer. Meanwhile, manual updating is the way to go.

          The beauty of development is – We got to stay ahead of everyone 🙂

  10. Hi Ranjith,
    How do I use a conditional statement like below to find if an element is not present

    If driver.WaitNotElement(By.ID(“loadMore”))

    I get a “Type Mismatch Error”

    1. Hi Salam,

      If you are trying to check if Element is present or not then this code should do the work.

      Set mybutton = bot.FindElementById(“someid”, timeout:=0, Raise:=False)
      If mybutton Is Nothing Then
      MsgBox (“no element found”)
      End If

      But if you are trying to wait till the element becomes available the check the updated article. I’ve added a new section – Wait for element in Selenium VBA.

  11. I am very happy that i found your site finally. This site is awesome and very informative about different stuffs on complicated topics about which thousand others barely dare to deal with. Anyways, i got an issue in my written code. Gonna paste it underneath. Something is wrong with this. Every time i run it, i get an error showing “run time error 13, type mismatch”. By the way, i am running this code into my excel VBA editor.

    Here is the code:

    Any help would be greatly appreciated. Thanks in advance.

    1. I have already found the error and that is “driver.FindElementByClass(“info”)”, whereas the proper calling should be “driver.FindElementsByClass(“info”)”. By the way, can i run the code using seleniumwrapper.webdriver instead of webdriver.

    2. Hi Shahin, There are few mistakes in your code. Use FindElementsByClass instead of FindElementByClass in set posts line because there are multiple elements. Define posts and post as object instead of webelements.

      Here’s the working code –

      Seems like you are using an old version of Selenium VBA which has OPEN method. Install latest version and use GET method. Phantomjs is kind of unstable. It works sometimes, doesn’t work sometimes due to timeout issues. Use Chrome instead, It works perfectly. Also, try HTTP request method which I’ve used here – It will be 20 times faster than selenium 🙂

  12. This seems to be a great tutorial but I failed to begin because of error at the very first line.

    bot.Start "chrome", ""

    gives me `Run-time error 0, WebRequestError,

    when I executing :

    bot.Start "firefox"

    i get:

    `gives me Run-time error 21, TimeoutError, Firefox failed to open listening port within 15.s. Do you know how to deal with it?

  13. Hi ,
    Great beginner tutorial to get me started, thanks! I’m wondering though; can I late bind with selenium:
    I would like to create a macro that runs without library references. For IE that was just a case of swithcing
    Dim bot As New InternetExplorer to
    Dim bot As Object: Set bot = CreateObject("InternetExplorer.Application")
    and leaving everything else the same
    How do I do this for Selenium?
    Dim bot As Object: Set bot = CreateObject("Selenium.WebDriver") gives a run time error for ie, and an unknown error for edge. Is there something else I should try?

  14. Im getting automation error while using this code

    Public Sub seleniumtutorial()
    Dim bot As New WebDriver
    bot.Start “chrome”, “”
    bot.Get “/”
    bot.TakeScreenshot.SaveAs (ActiveWorkbook.Path + “/screenshot.jpg”)
    ‘quit method for closing browser instance.
    End Sub

    I have selenium wrapper installed and used it with latest chrome driver. am i missing anything?

    It says runtime error(xxxxxxxxx)
    Automation error

  15. Thanks a lot, wow, didnt know it was that easy, but now i have another problem, there is no id in the webpage im trying to scrape, all are in class name it looks like this


    GARDENA CANADA is the string im trying to extract, but the span calss sc-attribute is same for all attributes, the attribute name is sc-grid-cell sc-grid-cell-brand but when i tried to extract the value it says some error as compound xxxxx. seems like the space between the attribute is problem, any help is greatly appreciated.

  16. sent you an email with the snippet as im unable to attach the same her in the comment, subject would be: Gardena WEbscraping-Ashok

    Please assist ..

  17. These examples show how to start the browser…is there a way to capture an already existing instance of a browser for manipulation? Thanks.

    1. Hi John, Unfortunately, there’s no way to control an existing browser instance which was opened manually 🙁

  18. Thanks a lot for this useful article
    I have installed Selenium the latest version and when trying the first code .. I got chrome crashed (Chrome is the latest version too)
    Any idea?

  19. I found this folder “SeleniumBasic” in Program Files and I copied the “chromedriver.exe” and replaced the old one .
    Then I tried this code
    Public Sub seleniumtutorial()
    ‘References : Selenium Type Library
    Dim bot As New WebDriver

    bot.Start "chrome", ""

    End Sub

    The google chrome appeared for a second then disappeared. Any idea?

    1. The Browser will quit once it completes execution of code. Write more code or use bot.sleep or application.wait depending on your context.

  20. Thank you very much for your patience
    I have added this line : bt.Sleep
    and I encountered “chromedriver.exe has stopped working” and there is a warning message of “Disable Developer mode extensions”
    I am using the latest version of chrome (Version 61.0.3163.91 (Official Build) (32-bit)) and the latest version of selenium (SeleniumBasic-

  21. I have solved this by copying “chromedriver.exe” in the lnik you attached to the “SeleniumBasic” folder and now no errors but I got in the address bar “data:,” and there’s a hint “Chrome is being controlled by automated test software”…

    1. Hi Ravi, You can use SendKeys method to send keystrokes. Ex: bot.FindElementById(“identifier”).SendKeys(keys.Enter)

      1. Thank you very much for reply ..
        Is it working even if the desired page not shown?
        Another question : is there a way to make the driver hidden such as PhantonJSDriver?

        1. If the element is hidden then selenium cannot find it. If the element is not hidden and the browser is just headless then selenium can still sendKeys. You can use phantomJS itself instead of chrome.

          1. Thank you very much for quick reply
            Last question : how to make the desired tab to be the active tab .. all the time while running the code using selenium?

  22. Hello, great post. I have some question… How can I set one or more firefox profile? I have seems code for java but not to vba. Thanks!!

    1. Hi. I solved my previous question. However, the browser does not load the page I entered and send me this:

      Run-time error ’21’:
      firefox failed to open the listening port whithing 15s

      I have read that it is necessary to use geckodriver for firefox version 48 and higher. I have already downloaded it but I do not know how to use it through VBA.

      1. Did you ever find out how to get geckodriver working with later versions of firefox, I’m trying to do this now and am stuck with how to proceed!

  23. Hi, can you help. I have played with Selenium for a good while and had to get a new PC. Installing Selenium went fine but it just reports automation error at the first step ‘driver.Start “chrome”, “”. The same code still works on my old PC.
    Are there other bits of MS software that need to be installed that might have already been on my previous PC?

  24. Hello. How can I press ctrl+shift J in chrome.?

    I used this for firefox and works:

    driver.FindElementById(“my-id”).SendKeys Keys.Control + Keys.Shift, “k”

    for chrome I must replace k with j to open console.

    To evaluate the operation of the keys I tried keys.control, “v” and works but the use of keys.control + keys.shift, “j” or only keys.F12 does not work for me in chrome, however in firefox yes.

  25. Could you please let me know if I can register the DLLs manually and not
    install the setup on my client systems. I would like to know the DLL list which
    i need to register as well as how i can register them as I do not have access
    to install this setup on client systems.

    Please help

  26. Hello,
    I’m getting Rub Time Error = 21

    Firefox failed to open the listening port within 15s

  27. Dear Ranjith,
    this is already a good explanation and the bunch of information on the selenium web driver. thank you again.

    I want to study the whole “objects” of the selenium driver. Like,
    in bot.get(“/”) statement,
    we understand the working of .get object.

    so selenium web driver may have consisted of many objects which can be useful for any task.

    can you please tell me, where we can learn all?

    1. Hi Kamal, You can use VBA autocomplete to view all the available methods and properties. Type bot. and VBA will show you all the methods available. The syntax of the methods will be shown once you type the method name with a bracket. Ex: bot.get(

  28. Hi all, these Many days I was using selenium wrapper and it worked fine. But today I faced issue with the Chrome driver. I am not able to type data in a field and click any buttons. I didn’t receive any error, the page opened in chrome was in the same page. What is the solution for this? Why it suddenly not working? Please give me some solution.

  29. Hi Ranjith,
    After I lernt and use json tutorial from you, I started with selenium now. I started with Simple Example provided by you.
    I have received an error, the details are as follow:
    Chrome: Version 65.0.3325.181 (Official Build) (64-bit)
    Error on line: bot.Start “chrome”, “”
    Error in VBA: WebRequestError The underlying connection was closed. An unexpeted error occurred on a receive.
    Note: It opens new chrome window and alert displayed regarding “Disable developer mode extensions” with “Disable” and “Cancel” buttons.
    Refferances added in VBA:
    Visual Basic For Applications
    Microsoft Excel 16.0 Object Library
    Microsoft Office 16.0 Object Library
    OLE Automation
    Selenium Type Library (downloaded from the github link you mentioned)
    Please guide further.
    Thanks in advance,
    Jigar B

  30. Hi Ranjith,
    I have been using IE for browser automation with MS Access VBA.
    For various reasons, I need to convert one sub to Chrome and I am having a heck of a time getting it figured out.
    Can you help me doing a little conversion of my IE code for selenium.
    I can send you my current code and the source code for the pages I am working with (it is a secure site, so I can’t give you the login).
    Thank you in advance for your help!

  31. Hi Ranjith,
    I’m facing a tough problem, need your suggestions, I just make a try on a automation with selenium & excel vba. My target url is designed to generate a new pop up from the just beginning , I need to type username and password on the newly pop up window, and login to select some menu to download files.
    My codes can open Firefox with the url, but cannot recognize the element by all kinds of methods (I can see the element’s id and name by right click on mouse choosing inspect the element )in the login window, I guess my codes even cannot recognize the new window. Because after pop up I use “windows.count” the feedback is 1. Is there method to recognize the new window, and then take use of its elements to type in. Thanks sincerely!

    1. Hi Sunyoung
      Did you ever figure this out? I have this same issue and I need to know how to get to the new window. Thanks

  32. I keep getting runtime error 11 element not visible for line:


    The btn clearly is visible because the line before completes in terms of inputting the demonstration value with:

    bot.FindElementByName(“q”).SendKeys (currCell.Value)

    I introduced waits but that didn’t seem to make a difference.

    How do I resolve this please? If a loop is required please could you show how it would be applied to your demo example.


  33. Hi Ranjith,
    I’m new in web scrapping world using VBA, your post is very useful, thank you.
    I would like to avoid Firefox browser or Opera Browser (I use them mostly) load images. In web there are post for this but using Python, I have tried to write a script for VBA, but it does not work. If you have information I would like to know about how webdriver profiles and preferences works in VBA.
    I have used this:

    Private bot As Selenium.WebDriver
    Private Sub CommandButton1_Click()
    Set bot = New Selenium.WebDriver

    bot.SetPreference "permissions.default.image", 2
    bot.Start "firefox", ""
    bot.Get "/"
    End Sub

    But, as I mentioned it does not work, I mean Firefox browser opens, loads the website but images are load too. I’m using Firefox 35, SeleniumBasic 2.09 and MS Excel 2010. I would be thank if you have information as for Firefox as Opera.
    Congratulations for your website.!
    Thank You again.

  34. Hey Folk,
    Q1) How to over write input value instead of appending to old value (Selenium WebDriver VBA)
    Example: I would like to fill the input box in the form by using this syntax (VBA)
    .FindElementByXPath(“//*[@id=’cf_1364′]”).SendKeys “Not Available”
    but, “Not Available” String appending to old input value.

    Q2) How to pass Shortcut keys (Selenium WebDriver VBA)
    Example: like Application.keys “{TAb}”

  35. hi, i’m zairy. thanks 4 sharing.
    may u help me?

    i hav try ur script to my project but i end up with this notification.
    Public Sub seleniumtutorial()
    Dim bot As New WebDriver
    bot.Start “chrome”, “;
    bot.Get “/”
    bot.TakeScreenshot.SaveAs (ActiveWorkbook.Path + “/screenshot.jpg”)
    ‘quit method for closing browser instance.
    End Sub

    session note created exception
    from unknown error: Runtime.executionContextCreated has invalid ‘context’ ….”

    please help…

  36. Your tutorial is so useful, but the project has not been updated until 2016.Did the author update the version somewhere else? Thank you

  37. Hi,
    I have several questions about the vba code. i’m not sure where to find the materials to learn to execute the code.
    1) I want to click on this button with
    I tried the findElementByName, then by ID. But it didn’t work. Should I try with findElementsbyClass. But how I do that?
    2) I want to select Green in this code: Dyed

    with: obj.FindElementByName(“SelectedFavoriteColor”).AsSelect.SelectByValue (G)
    but it wouldn’t work. You know why? Please let me know. Thanks

  38. Hi Ranjith,

    Could you kindly explain me how can i solve the IE issu about the zoom in selenoum VBA?

    Thanks in advance

  39. HI,
    I just get a
    Run-time error ’33’
    Application-defined or object defined error

    when i run the Start method…
    Any help please?

  40. Hi,

    I have installed the SeleniumBasic v2.0.9.0, however after installing , it shows an error as “couldn’t be installed because it appears to be corrupt”. Any clue to fix this

  41. In order for the Opera to work well with Selenium, you have to install it in the Program Files (x86) and replace its original driver in folder: C:\Users\user\AppData\Local\SeleniumBasic\
    with the one coming from github:

    When I first tried to start Opera with VBA it didn’t work as it installs by default in a different location. You need to specify it yourself to be Program Files (x86).
    Then you just run it as, say:

    Dim driver as New Webdriver

    driver.start “opera”, “”
    driver.get “/”

  42. Can anybody advise how to use geckodriver with VBA, please?
    I already know I cannot simply replace firefoxdriver.xpi in the SeleniumBasic folder with a geckodriver.exe, just like I would with operadriver or chromedriver.

    Everything I can find about geckodriver refers to Java or Python. Is there a way to use new versions of Firefox with Visual Basic?

    Please help if anyone know how to do it.

  43. Good Day

    I am attempting to click on a folder created on google drive using Selenium VBA. I have attempted it using the following code:

    Dim chrome As New WebDriver
    ‘Open Google Drive Homepage
    chrome.Start “chrome”, “;
    chrome.Get “/”
    ‘Type in username/email address
    chrome.FindElementByName(“identifier”).SendKeys (“Myemail”)
    ‘Click Next
    ‘Wait to load
    chrome.Wait 3000
    ‘Type in password
    chrome.FindElementByClass(“whsOnd “).SendKeys (“Mypassword”)
    ‘Submit password
    chrome.Wait 10000
    ‘Open folder structure
    chrome.Wait 10000
    ‘Click on Questionnaires folder
    chrome.FindElementByCss(“.fe-Mh-cb > span:first-child > .fe-pg-Oc-tc”).Click

    I have managed to automate the login process on Google and the code is executed up until the last line of code and then the element is not found. I know it has something to do with syntax of finding the first child but I am not sure what it should be. Is it possible that you can assist please?

    The folder name on Google drive is ‘Questionnaires’ and the following HTML code appears upon inspecting element.


    Thank you in advance.

Leave a Reply

Your email address will not be published. Required fields are marked *