SergeyPirogov / webdriver_manager

Apache License 2.0
2.05k stars 456 forks source link

Chromedriver is not retrun correct path , exact location of error/ need to modify in this function "__get_binary(self, files, driver_name)" #667

Open DarshanUTHUK opened 3 months ago

DarshanUTHUK commented 3 months ago
There are three files ['chromedriver-win32/LICENSE.chromedriver','chromedriver-win32/chromedriver.exe', 'chromedriver-win32/THIRD_PARTY_NOTICES.chromedriver']  in the current version of chromedriver download path. so as code tells if 'LICENSE' in f:
            continue but next two iteration will be .exe and THIRD_PARTY_NOTICES.chromedriver so   this logic will be not so good for this function.  

def __get_binary(self, files, driver_name): if not files: raise Exception(f"Can't find binary for {driver_name} among {files}")

    if len(files) == 1:
        return files[0]

    for f in files:
        if 'LICENSE' in f:
            continue
        if driver_name in f:
            return f

    raise Exception(f"Can't find binary for {driver_name} among {files}")

we can update like this as follows:-

def __get_binary(self, files, driver_name):
    if not files:
        raise Exception(f"Can't find binary for {driver_name} among {files}")

    if len(files) == 1:
        return files[0]

    if not driver_name.__contains__(".exe"):
        driver_name = driver_name.join(".exe")

    for f in files:
        if 'LICENSE' in f:
            continue
        if driver_name in f:
            return f

    raise Exception(f"Can't find binary for {driver_name} among {files}")
DarshanUTHUK commented 3 months ago

as driver_name contains only a 'chromedriver'....its bettter check with extension also. where this path is used in drivers.json and also for driver executable_path .

DarshanUTHUK commented 3 months ago

@SergeyPirogov please look this issue with solutions which i have sent in this

thomvas commented 3 months ago

as driver_name contains only a 'chromedriver'....its bettter check with extension also. where this path is used in drivers.json and also for driver executable_path .

I think this solution is only valid for Windows, but on MacOS and Linux there is no exe extension, so I don't think this type of control is a good idea

DarshanUTHUK commented 3 months ago

as driver_name contains only a 'chromedriver'....its bettter check with extension also. where this path is used in drivers.json and also for driver executable_path .

I think this solution is only valid for Windows, but on MacOS and Linux there is no exe extension, so I don't think this type of control is a good idea

Yeah got your point

DarshanUTHUK commented 3 months ago

what this code
def __get_binary(self, files, driver_name): if not files: raise Exception(f"Can't find binary for {driver_name} among {files}")

    if len(files) == 1:
        return files[0]

    for f in files:
        if 'LICENSE' in f:
            continue
        if driver_name in f:
            driver_extension = "." + driver_name
            if driver_extension not in f:
                return f

    raise Exception(f"Can't find binary for {driver_name} among {files}")
DarshanUTHUK commented 3 months ago

please check above code tell whether this can usefull

CalebePrates commented 2 months ago
chrome_path = ChromeDriverManager().install()
if "THIRD_PARTY_NOTICES.chromedriver" in chrome_path:
    chrome_path = chrome_path.replace("THIRD_PARTY_NOTICES.chromedriver", "chromedriver")