7

I am having problems even setting up Selenium for VBA. I have been reading online on what to do, download the selenium (https://github.com/florentbr/SeleniumBasic/releases/tag/v2.0.9.0) add extension and etc. However, I am still struggling to get it to work.

Even writing a simple code like the following which I have found online:

Public Sub Demo()
    Dim d As WebDriver
    Set d = New ChromeDriver
    Const URL = "https://www.google.com/"

    With d
        .Start "Chrome"
        .get URL
        .FindElementById("lst-ib").SendKeys "Selenium basic GitHub"
         .FindElementsByTag("form")(1).FindElementByCss("input[value='Google Search']").Click
        '.Quit
    End With
End Sub

Gives me an Automation error.

I would like to use google chrome in the same way as internet explorer. I would appreciate any help with setting up selenium , and I know my question can be seen as silly.

YasserKhalil
  • 9,138
  • 7
  • 36
  • 95
Wolf Kolev
  • 121
  • 1
  • 1
  • 8
  • 1
    Did you Check the Reference `Selenium Type Library` ? If not select the Reference in Tools>References – Mikku Jul 26 '19 at 09:11
  • I did add the reference Selenium Type Library but for some reason it still gives me the automation error – Wolf Kolev Jul 26 '19 at 09:17
  • Which line shows the error ? – Mikku Jul 26 '19 at 09:17
  • Set d = New ChromeDriver And the automation error that it gives me is : Run time error : '-2146232576 – Wolf Kolev Jul 26 '19 at 09:22
  • That usually happens because of the Reference. Not sure what it is in your case. – Mikku Jul 26 '19 at 09:24
  • I am confused as well as this is what it says everywhere I read, Unless somehow excel does not have access to this extension even though I have added it. Not sure if I need to download this extension from somewhere else as well or If i need to set it up somehow to use google chrome – Wolf Kolev Jul 26 '19 at 09:28
  • 1
    Do you have the right chromedriver.exe for your version of chrome and is that driver in the selenium folder? – QHarr Jul 26 '19 at 11:06
  • I will be honest and not really sure how to check compatability with the chrome driver versions or where to check them. The chrome I have installed is Version 75.0.3770.142. How to check what driver do I have? What exactly should I add to the selenium folder. I would expect to have to put something in the following folder C:\Users\MyUserName\AppData\Local\SeleniumBasic. I might sound silly but I appreciate any help and again thanks for the quick responses – Wolf Kolev Jul 26 '19 at 12:25
  • https://chromedriver.storage.googleapis.com/index.html?path=75.0.3770.140/ then if windows you want chromedriver_win32.zip . Unzip and put the chromedriver.exe in the selenium folder (Replace the existing one if there is already one. – QHarr Jul 26 '19 at 13:32
  • so I did that and put it into the folder. Not sure if it is a problem as the driver end on 140 and my google chrome ends on 142. Again I do get the same automation error. Also when I click on the chrome driver I get the following message : Only local connections are allowed. Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code. – Wolf Kolev Jul 26 '19 at 15:20

2 Answers2

23

First of all, go to control panel and uninstall previous installation of selenium and then follow the steps 1- Download the latest version of chrome and make sure of the version of Chrome from Help >> About Google Chrome. You would see something like that Version 75.0.3770.142 (Official Build) (32-bit)

2- Download the latest version from the LINK

3- Download the chromedriver from the follwoing LINK Make sure of the version that suits your chrome version As for the Google Chrome version I posted the most suitable version of chromedriver is ChromeDriver 75.0.3770.140

  1. Now setup SeleniumBasic >> After setup unzip the chromedriver file chromedriver_win32.zip and copy the chromedriver.exe to the path of selenium Here's two possibilties: First >> C:\Program Files\SeleniumBasic Second >> C:\Users\%username%\AppData\Local\SeleniumBasic Copy the chromedriver.exe to the SeleniumBasic path

  2. Open new blank excel file >> Press Alt + F11 (Visual Basic Editor) >> Tools >> References >> Selenium Type Library

  3. Insert new module and paste the following code to test

Sub Test()
    Dim bot         As New WebDriver
    
    bot.Start "chrome", "https://www.google.com"
    bot.Get "/"
    Stop
End Sub
YasserKhalil
  • 9,138
  • 7
  • 36
  • 95
  • Followed the steps, still continues to give the exact same error, Tomorrow I will try to find a different computer and try on it to see if it gives a different result. – Wolf Kolev Jul 26 '19 at 21:29
  • @Wolf Kolev Which windows version do you use (32 Bit or 64 Bit) ..? May be there are specific firewall or antivirus that prevents SeleniumBasic... – YasserKhalil Jul 27 '19 at 04:11
  • I am using the 64 bit and I am wondering whether that chrome drive is not working as it says 32 bit on it. I will check my firewall setting as well to double check if something is stopping selenium from working. – Wolf Kolev Jul 27 '19 at 12:42
  • No problem. I am using Windows 64Bit and Chrome 64 Bit / Chrome 32 Bit and both works fine with chromedriver.exe (which is 32Bit) .. – YasserKhalil Jul 27 '19 at 13:19
  • I am out of ideas, not sure why it is not working, I even turned firewall off and still does not work – Wolf Kolev Jul 31 '19 at 19:14
  • 2
    YasserKhalil, you are the king of selenium, Reinstalled my net framework and it is working now, Huge thanks for the help, for the quick response and the fact that for the past week you kept checking on here and help me out, huge huge thanks – Wolf Kolev Aug 01 '19 at 20:23
  • 1
    Now just left to learn how to navigate with selenium in the same way as I do in internet explorer – Wolf Kolev Aug 01 '19 at 20:38
  • @Wolf Kolev You are so welcome. Glad I can offer some help. Hope this will help the other members too. Regards – YasserKhalil Aug 02 '19 at 03:51
  • 1
    You are a legend, works, thank you very much for this answer, Yasser! –  Nov 02 '20 at 20:39
  • @YasserKhalil can you maybe update your answer with what turned out to be the solution in the end? I have the same issue as WolfKolev and I am not sure how to get from there - was it an issue with the Net Framework? – Eleshar Jan 18 '21 at 17:04
  • @Eleshar Try installing NET Framework 3.5 – YasserKhalil Jan 18 '21 at 18:18
  • Install 3.5 too. I think this will solve your problem. – YasserKhalil Jan 19 '21 at 12:27
  • 1
    @YasserKhalil I got 3.5 as well but I think you are right about the problem being in the framework. I have apparently an issue with the NET framework. Most of the time, my Excel crashes when opening a file with PowerQuery. It crashes on "Loading .Net Framework". When I do manage to open such a file, I succeed in running the function too. – Eleshar Jan 19 '21 at 12:28
2

I downgraded chrome.exe to one version lower downloads (off the selenium chrome webdriver site) in Users/?/AppData/Local/SeleniumBasic directory and it worked. ..running windows 10.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352