Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Softly download latest version on version mismatch #293

Closed
paulschmeida opened this issue Feb 3, 2022 · 11 comments · Fixed by #294
Closed

Softly download latest version on version mismatch #293

paulschmeida opened this issue Feb 3, 2022 · 11 comments · Fixed by #294
Assignees

Comments

@paulschmeida
Copy link

Today Google released Chrome 98.0.4758.81, but the latest Chromedriver version is 98.0.4758.48, which is compatible with this release. I propose webdriver_manager should download latest compatible version if there's a version mismatch, not just when the Chrome version is unknown.

@paulschmeida
Copy link
Author

I also just found that that latest release according to this: https://chromedriver.storage.googleapis.com/LATEST_RELEASE
is 97.0.4692.71, which is not true, because the current stable Chrome version is 98.0.4758.81 and current stable chromedriver version is 98.0.4758.48.

@aleksandr-kotlyar
Copy link
Collaborator

That's already should work like you describe. If not - please provide the webdriver_manager version and example of code to reproduce.

@paulschmeida
Copy link
Author

paulschmeida commented Feb 3, 2022

Oh, in that case I think it doesn't work like that when the version of Chrome browser is supplied manually. I have a different way of retrieving current Chrome browser version, which uses wind32api. I had to do it because I package my projects using pyinstaller and webdriver_manager uses subprocess to get chrome version, which is incompatible with pyinstaller and other packagers that create .exe out of python projects.

I could see if I can change the way webdriver_manager looks for Chrome version on Windows to use win32api, if you guys are interested?

This is a more reliable way that subprocess:

def _get_chrome_version(filename):
    try:
        info = win32api.GetFileVersionInfo(filename, '\\')
        ms = info['FileVersionMS']
        ls = info['FileVersionLS']
        return f'{win32api.HIWORD(ms)}.{win32api.LOWORD(ms)}.{win32api.HIWORD(ls)}.{win32api.LOWORD(ls)}'
    except:
        return 'Unknown version'

@aleksandr-kotlyar
Copy link
Collaborator

If you send 98.0.4758.81 to webdriver-manager as version, and chrome doesn't have a webdriver for it - so it fails - it's okay.
You should take 98 from 98.0.4858.81 and send 98 version to webdriver-manager. Than it will download right version of chromedriver.

@paulschmeida
Copy link
Author

paulschmeida commented Feb 4, 2022

I've tested both the release and the github version and it doesn't work like that. It tries to download this:
ValueError: There is no such driver by url https://chromedriver.storage.googleapis.com/98/chromedriver_win32.zip

and it fails.

Looking at the code, I don't believe that's how it webdriver-manager works. You need to supply the full version string and it needs to match and existing chromedriver version.

@aleksandr-kotlyar
Copy link
Collaborator

Provide code snippet how do you pass chromeversion to webdriver_manager.

@paulschmeida
Copy link
Author

paulschmeida commented Feb 4, 2022

So I get the Chrome version using the above function and I then initialize webdriver_manager with a version= argument:

# Chrome webdriver
chrome_filename = r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
driver = webdriver.Chrome(ChromeDriverManager(version=_get_chrome_version(chrome_filename)).install(), chrome_options=options)

_get_chrome_version returns a full version string like '98.0.4858.81'.

@paulschmeida
Copy link
Author

In the meantime I've sorted it out by adding a function which finds the latest chromedriver version for a given major version number from https://chromedriver.storage.googleapis.com/

It looks like this:

def _get_latest_chromedriver_version(major_version_number):
    r = requests.get('https://chromedriver.storage.googleapis.com/')
    all_versions = regex.findall(f'({major_version_number})(\.\d+\.\d+\.\d+)', r.text)
    return ''.join(all_versions[-1]) # Assumes results from above google xml are already sorted

and I now call webdriver_manager like this:

# Chrome webdriver
chrome_filename = r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
chromedriver_version = _get_latest_chromedriver_version(_get_chrome_version(chrome_filename).split('.')[0])
driver = webdriver.Chrome(ChromeDriverManager(version=chromedriver_version).install(), chrome_options=options)

but I think it would be interesting to see this type of graceful fallback directly in webdriver_manager.
Let me know what do you think.

@aleksandr-kotlyar
Copy link
Collaborator

aleksandr-kotlyar commented Feb 4, 2022

Even with your function - there is no way to get chromedriver version if chrome doesn't publish it.
You have '98.0.4858.81' version but Chrome published chromedriver with '98.0.4758.80'. win32api will not help you in this case because the version with .81 was not published.

@aleksandr-kotlyar
Copy link
Collaborator

The problem that should be solved is the more powerfull windows version reader than webdriver_manager has now. win32api seems to be a huge dependency which I will not recommend to include to this library. But maintainer can have another opinion. We need just one function from this library.

@paulschmeida
Copy link
Author

Even with your function - there is no way to get chromedriver version if chrome doesn't publish it. You have '98.0.4858.81' version but Chrome published chromedriver with '98.0.4758.80'. win32api will not help you in this case because the version with .81 was not published.

No, my code gets the latest published version for major browser version, so in this example it will get chromedriver '98.0.4758.80' for chrome browser '98.0.4858.81'. I already have it running in production.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants