florentbr / SeleniumBasic

A Selenium based browser automation framework for VB.Net, VBA and VBScript
BSD 3-Clause "New" or "Revised" License
432 stars 197 forks source link

no chromeriver.exe found in new versions of chrome driver #274

Open metic88 opened 1 year ago

metic88 commented 1 year ago

hi I downloaded ver. 118 of chrome driver for win64. But there is no chromeriver.exe in the zipped bundle to copy to selenuim folder. It seems that google is now publishing updates in a different way. can you please help me about this issue ?

GCuser99 commented 1 year ago

This url explains the current process: https://github.com/GoogleChromeLabs/chrome-for-testing#json-api-endpoints

Here is one of the endpoints exposed in the above link that contains the download urls for latest versions of Chrome: https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json

And from the above json, you will find the latest 64-bit driver for version 118: https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/118.0.5993.70/win64/chromedriver-win64.zip

metic88 commented 1 year ago

This url explains the current process: https://github.com/GoogleChromeLabs/chrome-for-testing#json-api-endpoints

Here is one of the endpoints exposed in the above link that contains the download urls for latest versions of Chrome: https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json

And from the above json, you will find the latest 64-bit driver for version 118: https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/118.0.5993.70/win64/chromedriver-win64.zip

many thanks

yamanjain commented 12 months ago

Use this VBA code to download Chromedriver to match your chrome version using the new process with Chrome for testing and even works with regular Chrome.

Function chkchromever()
    Tempfolder = "D:\"

    TempZipFile = Tempfolder & "Chromedriver.zip"
    SeleniumFolder = Environ$("ProgramW6432") & "\SeleniumBasic\"
    TempDrvFile = Tempfolder & "chromedriver-win64\" & "Chromedriver.exe"
    'Delete chromedriver.exe from temporary folder if it already exists
    If Dir(TempDrvFile) <> "" Then
        Kill (TempDrvFile)
    End If

    Set oShell = CreateObject("WScript.Shell")
    'Dim oShell  As New WshShell
    Dim objHttp As Object
    Set objHttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")

    'Get chrome version
    chrversion = CreateObject("WScript.Shell").RegRead("HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon\version")
    dotsarr = Split(chrversion, ".")
    leftchrver = dotsarr(0) & dotsarr(1)

    'Get chromedriver version
    gspath = Chr(34) & SeleniumFolder & "chromedriver.exe" & Chr(34)
    torun = gspath & " --version"
    errcode = oShell.Exec(torun).StdOut.ReadAll
    verarr = Split(errcode, " ")
    chrdrv = verarr(1)
    dotsarr2 = Split(chrdrv, ".")
    leftchrdrv = dotsarr2(0) & dotsarr2(1)

    'If major version mismatch (first two numbers) then ask if update required
    If leftchrver <> leftchrdrv Then
        myyn = MsgBox("Wrong version of chromedriver. " & vbCrLf & "Chrome version is " & chrversion & vbCrLf & "Chrome driver version is " & chrdrv, vbYesNo, "Do you want to update Chromedriver ?")
        If myyn = vbNo Then Exit Function
        'Get latest release version of chromedriver which matches installed version of Chrome
        url = "https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json"
        'url = "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_" & dotsarr(0)
        Call objHttp.Open("GET", url, False)
        Call objHttp.Send("")
        'Lack of Json
        version_number_json = objHttp.ResponseText
        Dim myJson As Object
        Set myJson = JsonConverter.ParseJson(version_number_json)
        version_number = myJson("channels")("Stable")("version")
        Set download_urls = myJson("channels")("Stable")("downloads")("chrome")
        Set download_urls = myJson("channels")("Stable")("downloads")("chromedriver")
        For Each keypair In download_urls
            If keypair("platform") = "win64" Then
                download_url = keypair("url")
                Exit For
            End If
        Next
        dotsarr3 = Split(version_number, ".")
        leftversion_no = dotsarr3(0) & dotsarr3(1)
        If leftchrver = leftversion_no Then
            'If chromedriver found then download it
            'download_url = "https://chromedriver.storage.googleapis.com/" + version_number + "/chromedriver_win32.zip"
            Call objHttp.Open("GET", download_url, False)
            Call objHttp.Send("")
            Set fileStream = New ADODB.Stream
            With fileStream
                .Open
                .Type = adTypeBinary
                .Write objHttp.ResponseBody
                .Position = 0
                .SaveToFile TempZipFile, adSaveCreateOverWrite
                .Close
            End With
            'Copy the new driver from .zip file to SeleniumBasic folder
            Set oApp = CreateObject("Shell.Application")
            oApp.Namespace(Tempfolder).CopyHere oApp.Namespace(TempZipFile).Items

            'Create batch file to copy chromedriver.exe to Seleniumbasic folder and run it using Administrator rights
            tmpbatpath = Tempfolder & "copychdrv.bat"
            'Check if Chromedriver downloaded successfully
            If Dir(TempDrvFile) <> "" Then
                Open tmpbatpath For Output As #1
                'Enable these if required to copy chromedriver.exe
                '        Print #1, "taskkill /f /im  GoogleCrashHandler.exe"
                '        Print #1, "taskkill /f /im  GoogleCrashHandler64.exe"
                '        Print #1, "taskkill /f /im  Chrome.exe"
                '        Print #1, "taskkill /f /im  Googleupdate.exe"
                If IsProcessRunning("Chromedriver.exe") Then
                    Print #1, "taskkill /f /im  Chromedriver.exe"
                End If
                Print #1, "copy " & Chr(34) & TempDrvFile & Chr(34) & " " & Chr(34) & SeleniumFolder & "Chromedriver.exe" & Chr(34) & "/y & pause"
                Close #1

                'MsgBox ("press ok to continue")
                'copy it now by running batch file
                success = ShellExecute(0, "runas", tmpbatpath, aPic, vbNullString, SW_SHOWNORMAL)
                MsgBox ("press ok to continue again")
            End If
            'Cleanup
            If Dir(TempZipFile) <> "" Then
                Kill (TempZipFile)
            End If
            If Dir(tmpbatpath) <> "" Then
                Kill (tmpbatpath)
            End If
        End If
        MsgBox ("Chromedriver updated")
    Else
        MsgBox ("All OK. Chromedrive version is " & chrdrv & " same as chrome version " & chrversion)
    End If
End Function

Function json_parse(Json, tag_beg, tag_end)
        loc_beg = InStr(Json, tag_beg)
        loc_beg = loc_beg + Len(tag_beg)
        loc_end = InStr(loc_beg, Json, tag_end)
        json_parse = Mid(Json, loc_beg, loc_end - loc_beg)
End Function