webdriver_manager icon indicating copy to clipboard operation
webdriver_manager copied to clipboard

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

Open DarshanUTHUK opened this issue 1 year ago • 7 comments

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 avatar Jul 26 '24 15:07 DarshanUTHUK

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 avatar Jul 26 '24 15:07 DarshanUTHUK

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

DarshanUTHUK avatar Jul 26 '24 15:07 DarshanUTHUK

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

thomvas avatar Jul 26 '24 21:07 thomvas

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 avatar Jul 27 '24 08:07 DarshanUTHUK

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 avatar Jul 27 '24 08:07 DarshanUTHUK

please check above code tell whether this can usefull

DarshanUTHUK avatar Jul 27 '24 08:07 DarshanUTHUK

chrome_path = ChromeDriverManager().install()
if "THIRD_PARTY_NOTICES.chromedriver" in chrome_path:
    chrome_path = chrome_path.replace("THIRD_PARTY_NOTICES.chromedriver", "chromedriver")

CalebePrates avatar Aug 06 '24 18:08 CalebePrates