Python Webdrivermanager .install() does not work for edge in custom webdriver installation location
I use Webdrivermanager to update my drivers. But for the Edge browser I get errors.
elif preferred_browser == "Edge":
service = Edge_Service(EdgeChromiumDriverManager().install())
service.creationflags = CREATE_NO_WINDOW
driver = webdriver.Edge(service=service)
The Error:
File "PATH", line 1168, in start
service = Edge_Service(EdgeChromiumDriverManager().install())#r".\Drivers\edgedriver_win64\msedgedriver.exe"
File "PATH\microsoft.py", line 51, in __init__
super().__init__(path, log_level, print_first_line, cache_valid_range)
File "PATH\webdriver_manager\manager.py", line 13, in __init__
log("====== WebDriver manager ======", level=log_level)
File "PATH\webdriver_manager\logger.py", line 25, in log
_init_logger(level, name, first_line, formatter)
File "PATH\webdriver_manager\logger.py", line 19, in _init_logger
_logger.setLevel(level)
File "PATH\Python310\lib\logging\__init__.py", line 1443, in setLevel
self.level = _checkLevel(level)
File "PATH\Python310\lib\logging\__init__.py", line 201, in _checkLevel
raise TypeError("Level not an integer or a valid string: %r"
TypeError: Level not an integer or a valid string: None
Well I edited the manager, to save to another location. But it does work for Chrome and Firefox why not for edge...
modified driver_cache.py:
def save_file_to_cache(self, file: File, browser_version, driver_name, os_type, driver_version):
for directory in os.listdir(r'./Drivers/') :
if re.fullmatch('.*'+driver_name+'.*',directory):
shutil.rmtree(r'./Drivers/'+directory)
with open(r'./Drivers/drivers.json') as oldfile:
data = oldfile.read().split("\n")
oldfile.close()
i = 0
new_data = []
while i < len(data):
if driver_name in data[i]:
i += 4
continue
new_data.append(data[i])
i += 1
with open(r'./Drivers/drivers.json', 'w') as newfile:
newfile.write("\n".join(new_data))
data = yaml.load(open(r'./Drivers/drivers.json'),Loader=yaml.FullLoader)
data = json.dumps(data)
data = data.replace("'",'"')
with open(r'./Drivers/drivers.json', 'w') as newfile:
newfile.write(data)
path = r".\\Drivers\\" + driver_name + "_" + driver_version
archive = save_file(file, path)
files = archive.unpack(path)
binary = self.__get_binary(files, driver_name)
binary_path = os.path.join(path, binary)
self.__save_metadata(browser_version, driver_name, os_type, driver_version, binary_path)
log(f"Driver has been saved in cache [{path}]")
return binary_path
modified microsoft.py:
class EdgeChromiumDriverManager(DriverManager):
def __init__(
self,
version="latest",
os_type=utils.os_type(),
#path=None,
path=r".\\Drivers",
name="edgedriver",
url="https://msedgedriver.azureedge.net",
latest_release_url="https://msedgedriver.azureedge.net/ LATEST_RELEASE",
log_level=None,
print_first_line=None,
cache_valid_range=1,
):
super().__init__(path, log_level, print_first_line, cache_valid_range)
self.driver = EdgeChromiumDriver(
version=version,
os_type=os_type,
name=name,
url=url,
latest_release_url=latest_release_url,
)
Just to compare the edited and working chrome.py:
class ChromeDriverManager(DriverManager):
def __init__(self, version="latest",
os_type=utils.os_type(),
#path=None,
path=r".\Drivers",
name="chromedriver",
url="https://chromedriver.storage.googleapis.com", latest_release_url="https://chromedriver.storage.googleapis.com/LATEST_RELEASE",
chrome_type=ChromeType.GOOGLE,
log_level=logging.INFO,
print_first_line=True,
cache_valid_range=1):
super().__init__(path, log_level=log_level, print_first_line=print_first_line,
cache_valid_range=cache_valid_range)
self.driver = ChromeDriver(name=name,
version=version,
os_type=os_type,
url=url,
latest_release_url=latest_release_url,
chrome_type=chrome_type)
I am sorry but I have no idea :(
Best Regards Christian
Okay,
it was a Problem with the logger of Webdrivermanager.
For microsoft.py I had to import logging and make some changes for the log_level:
class EdgeChromiumDriverManager(DriverManager):
def __init__(
self,
version="latest",
os_type=utils.os_type(),
#path=None,
path=r".\\Drivers",
name="edgedriver",
url="https://msedgedriver.azureedge.net",
latest_release_url="https://msedgedriver.azureedge.net/LATEST_RELEASE",
log_level=logging.INFO,
print_first_line=None,
cache_valid_range=1,
):
super().__init__(path, log_level, print_first_line, cache_valid_range)
self.driver = EdgeChromiumDriver(
version=version,
os_type=os_type,
name=name,
url=url,
latest_release_url=latest_release_url,
)
EDIT:
I created a custom_webdriver_manager