2

我正在尝试初始化 MSedge 浏览器并收到错误消息。

from selenium import webdriver
from selenium.webdriver.edge.service import Service
from webdriver_manager.microsoft import EdgeChromiumDriverManager

s=Service(EdgeChromiumDriverManager().install())
driver = webdriver.Edge(service=s)
driver.get('https://www.google.com')

错误声明:

TypeError                                 Traceback (most recent call last)
<ipython-input-2-4e36192a99d3> in <module>
      3 from webdriver_manager.microsoft import EdgeChromiumDriverManager
      4 
----> 5 s=Service(EdgeChromiumDriverManager().install())
      6 driver = webdriver.Edge(service=s)
      7 driver.maximize_window()

~\Anaconda3\lib\site-packages\webdriver_manager\microsoft.py in __init__(self, version, os_type, path, name, url, latest_release_url, log_level, print_first_line, cache_valid_range)
     49         cache_valid_range=1,
     50     ):
---> 51         super().__init__(path, log_level, print_first_line, cache_valid_range)
     52         self.driver = EdgeChromiumDriver(
     53             version=version,

~\Anaconda3\lib\site-packages\webdriver_manager\manager.py in __init__(self, root_dir, log_level, print_first_line, cache_valid_range)
     10         self.driver_cache = DriverCache(root_dir, cache_valid_range)
     11         if os.environ.get('WDM_PRINT_FIRST_LINE', str(print_first_line)) == 'True':
---> 12             log("\n", formatter='%(message)s', level=log_level)
     13         log("====== WebDriver manager ======", level=log_level)
     14 

~\Anaconda3\lib\site-packages\webdriver_manager\logger.py in log(text, level, name, first_line, formatter)
     23 def log(text, level=logging.INFO, name="WDM", first_line=False, formatter='[%(name)s] - %(message)s'):
     24     """Emitting the log message."""
---> 25     _init_logger(level, name, first_line, formatter)
     26     loggers.get(name).info(text)

~\Anaconda3\lib\site-packages\webdriver_manager\logger.py in _init_logger(level, name, first_line, formatter)
     17         handler.setFormatter(formatter)
     18         _logger.addHandler(handler)
---> 19         _logger.setLevel(level)
     20         loggers[name] = _logger
     21 

~\Anaconda3\lib\logging\__init__.py in setLevel(self, level)
   1407         Set the logging level of this logger.  level must be an int or a str.
   1408         """
-> 1409         self.level = _checkLevel(level)
   1410         self.manager._clear_cache()
   1411 

~\Anaconda3\lib\logging\__init__.py in _checkLevel(level)
    195         rv = _nameToLevel[level]
    196     else:
--> 197         raise TypeError("Level not an integer or a valid string: %r" % level)
    198     return rv
    199 

TypeError: Level not an integer or a valid string: None

我正在使用 webdriver_manager 3.5.2 和 selenium 4.0.0 请帮助我解决问题。如果您需要任何详细信息,请告诉我。先感谢您

4

1 回答 1

3

这是 webdriver_manager 3.5.2 的问题。是webdriver_manager的logger的问题。有关更多信息,您可以参考此问题此拉取请求

您可以根据拉取请求通过编辑 webdriver_manager 的源代码来解决此问题。您可以编辑webdriver_manager/microsoft.py文件,添加import logging和更改log_level=Nonelog_level=logging.INFO. 然后它可以很好地与 Edge 驱动程序一起使用。

于 2021-12-21T03:28:42.390 回答