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.

selenium_ie_meme

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 VB.net 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", "http://google.com"

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", "http://google.com"
bot.Get "/"
bot.TakeScreenshot.SaveAs (ActiveWorkbook.Path + "/screenshot.jpg")
bot.Quit
'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.

selenium_vba_tutorial_1

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", "http://google.com"
bot.Window.Maximize

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.FindElementByName("btnG").Click
bot.Wait 1000
bot.TakeScreenshot.SaveAs (ActiveWorkbook.Path + "/screenshot_" + cell.Value + ".jpg")
Next
bot.quit

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.

selenium_VBA_tutorial_2

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")
else 
myelement.Click
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.

Ranjith kumar
4.5 8 votes
Article Rating
Subscribe
Notify of
guest

139 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Amit
Amit
7 years ago

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

Regards

satyanarayanan
satyanarayanan
7 years ago

How to get the web results in the excel at the same time.

Mukhtar
Mukhtar
7 years ago

Nice article, well described. I have been searching the web for an info closely related to this. I want to use VB.net 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 VB.net also, do you have an idea how I can go about this? Thanks in advance.

Mukhtar
Mukhtar
7 years ago
Reply to  Ranjith kumar

Thanks Ranjith,

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

D Satyanarayanan
D Satyanarayanan
7 years ago

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”, “http://electoralservicessearch.azurewebsites.net/searchbyname.aspx”
bot.Window.Maximize
For Each Cell In rng
bot.Get “/”
bot.FindElementByName(“txt_Epicno”).SendKeys (Cell.Value)
bot.FindElementByName(“btn_Epic”).Click
bot.Wait 5000
Next
bot.Quit
End Sub
I need your help.

satyanarayanan
satyanarayanan
7 years ago
Reply to  Ranjith kumar

I need to get the details from the tamilnadu election website http://www.elections.tn.gov.in. 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
“http://electoralservicessearch.azurewebsites.net/searchbyname.aspx”. can you help me in this regard.

satyanarayanan
satyanarayanan
7 years ago
Reply to  Ranjith kumar

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”, “http://electoralservicessearch.azurewebsites.net/searchbyname.aspx”
bot.Window.Maximize
For Each Cell In rng
bot.Get “/”
bot.FindElementByName(“txt_Epicno”).SendKeys (Cell.Value)
bot.FindElementByName(“btn_Epic”).Click
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
Next
bot.Quit
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

YasserKhalil
YasserKhalil
6 years ago
Reply to  satyanarayanan

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

bot.Start "chrome", "http://electoralservicessearch.azurewebsites.net"
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))
bot.FindElementById("btn_Epic").Click

    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

Amit Shah
Amit Shah
3 years ago
Reply to  satyanarayanan

Hi satyanarayanan,

The URL is “https://electoralsearch.in/&#8221; and then the place where we type the EPIC No, there you have the Catcha Code, how did you get past that ?

http://electoralservicessearch.azurewebsites.net/searchbyname.aspx&#8221;
This above link can’t be accessed.
And also ,
There is no
http://www.elections.tn.gov.in. by clicking “searchvoters” , this way links to “https://electoralsearch.in/ ” this link only.

ravi
ravi
7 years ago
Reply to  Ranjith kumar

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

Ravi
Ravi
7 years ago
Reply to  Ranjith kumar

Hi,

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

Ravi
Ravi
7 years ago
Reply to  Ranjith kumar

Hi, let me also tell you i am on win 7 64 bit, office 2010

Ravi
Ravi
7 years ago
Reply to  Ranjith kumar

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”, “http://electoralservicessearch.azurewebsites.net”
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)

ravi
ravi
6 years ago
Reply to  Ranjith kumar

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.

satyanarayanan
satyanarayanan
7 years ago

Following codes inserted completes the looping:

On Error Resume Next
If Err.Number <> 0 Then
Err.Clear
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

D. Satyanarayanan
D. Satyanarayanan
7 years ago

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

D. Satyanarayanan
D. Satyanarayanan
7 years ago

Hi,
Thanks for the Example.

Erik
Erik
7 years ago

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

Public Sub seleniumtutorial()
Dim bot As New WebDriver
bot.Start “edge”, “http://google.com”
End Sub

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

Erik
Erik
7 years ago

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

Riley
Riley
7 years ago

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.

Todd Baker
Todd Baker
7 years ago

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.”

Code:
Sub OpenChrome()
Dim selenium As New WebDriver
selenium.Start “chrome”, “http://www.google.com”
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?

Todd Baker
Todd Baker
7 years ago
Reply to  Ranjith kumar

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

SessionNotCreatedError
session not created exception
from unknown error: Runtime.executionContextCreated has invalid
‘context’:
{“auxData”:{“frameId”:”2392.1″,”isDefault”:true},”id”:1,”name”:””,”orig

(Session info: chrome=54.0.2840.99)”

Does this error look familiar?

Salam
Salam
7 years ago

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”

shahin2137
7 years ago

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: https://bin.codingislove.com/eridenoxig.vbs

Any help would be greatly appreciated. Thanks in advance.

shahin2137
7 years ago
Reply to  shahin2137

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.

shahin2137
7 years ago

Thanks, sir. I’m really indebted to you for your kind reply. I am being able to write this code using selenium because of your blog. Thanks again.

Claudio D'Antonio
7 years ago

Thank you so much Ranjith, this article and other stuff in coding is love are helping me so much in enriching data for marketing purposes. Thank you, thank you, thank you!!

Junnel Camingawan
6 years ago

Hi Ranjith,
Can you please help?
I got an updated Selenium as per your advised above but got an error on
data:, in Chrome. In VBA, Runtime error ‘0’ : webrequesterror.
Thanks

Junnel

PeteR
PeteR
6 years ago

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

bot.Start "chrome", "http://google.com"

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 127.0.0.1:11423 within 15.s. Do you know how to deal with it?

Greedo
Greedo
6 years ago

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?

ashok
ashok
6 years ago

Im getting automation error while using this code

Public Sub seleniumtutorial()
Dim bot As New WebDriver
bot.Start “chrome”, “http://google.com”
bot.Get “/”
bot.TakeScreenshot.SaveAs (ActiveWorkbook.Path + “/screenshot.jpg”)
bot.Quit
‘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

ashok
ashok
6 years ago

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 CANADACOR

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.

ashok
ashok
6 years ago

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 ..

John
John
6 years ago

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

Yasser
Yasser
6 years ago

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?

Yasser
Yasser
6 years ago

I already found this link but I couldn’t find “SeleniumBasic” folder in Local. That’s weird

Yasser
Yasser
6 years ago

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", "http://google.com"

End Sub

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

Yasser
Yasser
6 years ago

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-2.0.9.0)

Yasser
Yasser
6 years ago

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”…
Regards

Ram
Ram
6 years ago
Reply to  Yasser

have you fix this issue please tell me

Yasser
Yasser
6 years ago
Reply to  Ram

It is solved partially .. Now I could test some codes and they are working

Ravi
Ravi
6 years ago

Hi Ranjith,

Could you please let me know how to hit keyboard keys, ex I want to press enter Key

YasserKhalil
YasserKhalil
6 years ago

Is there another way to type a text in inputbox instead of using SendKeys ?

YasserKhalil
YasserKhalil
6 years ago
Reply to  Ranjith kumar

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?

YasserKhalil
YasserKhalil
6 years ago
Reply to  Ranjith kumar

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?

adam
adam
6 years ago

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!!

adam
adam
6 years ago
Reply to  adam

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

Run-time error ’21’:
timeouterror
firefox failed to open the listening port 127.0.0.1:57348 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.

Thomas Granger
Thomas Granger
4 years ago
Reply to  adam

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!

Ian
Ian
6 years ago

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”, “http://google.com”. 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?

Scott
Scott
6 years ago

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.

Jone
Jone
6 years ago

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

KAMAL BHARAKHDA
KAMAL BHARAKHDA
6 years ago

Hello,
I’m getting Rub Time Error = 21

TimeoutError
Firefox failed to open the listening port 127.0.0.1:57590 within 15s

jacek
jacek
4 years ago

Hi Kamal,

Have you managed to find a way to overcome the Firefox error with listening port opening failure?

KAMAL BHARAKHDA
KAMAL BHARAKHDA
6 years ago

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?

Gayathri
Gayathri
6 years ago

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.

Jigar B
Jigar B
6 years ago

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”, “http://google.com”
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

Renee
Renee
6 years ago

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!

Sunyoung
Sunyoung
5 years ago

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!

Bert
Bert
4 years ago
Reply to  Sunyoung

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

Quentin
Quentin
5 years ago

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

bot.FindElementByName(“btnG”).Click

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.

Thanks

Quentin
Quentin
5 years ago
Reply to  Quentin

I noticed it was a submit button so I changed the event to .Submit not .Click and it works fine.

YersonG
YersonG
5 years ago

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", "https://codingislove.com/browser-automation-in-excel-selenium/"
bot.Get "/"
bot.Window.Maximize
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.
Greetings.!

David
5 years ago

There’s also another similar project one can try: https://github.com/daluu/seleniumexceladdin

David
5 years ago

FYI, there is also a VBScript alternative to Selenium VBA: http://htejera.users.sourceforge.net/vbswebdriver/

RaviKumar
RaviKumar
5 years ago

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}”

MOHD ZAIRY FIRDAUS BIN
MOHD ZAIRY FIRDAUS BIN
5 years ago

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”, “http://google.com&#8221;
bot.Get “/”
bot.TakeScreenshot.SaveAs (ActiveWorkbook.Path + “/screenshot.jpg”)
bot.Quit
‘quit method for closing browser instance.
End Sub

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

please help…

蒋
5 years ago

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

gumi
gumi
5 years ago

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
Pink
Green
White
Natural
Red
Blue
Orange
None

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

Kamal Rajan
Kamal Rajan
5 years ago

Hi
How do i execute a javascript code to change the style of a HTML Element through my VBS?

Luis Fernando Merlano
Luis Fernando Merlano
5 years ago

Hi Ranjith,

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

Thanks in advance

deepak
deepak
5 years ago

how to attache a file by clicking browse button