解决ChromeDriver的WebDriverException: Compound class names not perm...

需积分: 0 0 下载量 128 浏览量 更新于2024-08-03 收藏 4KB TXT 举报
"WebDriverException-CompoundClassName.txt" 在软件测试自动化领域,特别是使用Selenium WebDriver进行Web应用测试时,可能会遇到“WebDriverException: unknownerror: Compound class names not permitted”这样的错误。这个错误通常出现在尝试定位具有复合类名的网页元素时,即在一个CSS选择器中使用了多个类名,而Selenium不支持这种用法。 首先,让我们深入理解错误信息。`WebDriverException`是Selenium WebDriver框架抛出的一种异常,表明在执行浏览器操作时发生了错误。在这个特定的错误中,"unknownerror: Compound class names not permitted"意味着你尝试使用的CSS选择器包含了复合类名(两个或更多类名用空格分隔),这在Selenium的ChromeDriver中是不被允许的。 错误日志中还包含了其他详细信息,如: - Session info: 这部分表示当前浏览器会话的信息,这里是Chrome版本35.0.1916.114。 - Driver info: 显示了使用的ChromeDriver版本(2.9.248315)以及运行的操作系统(Windows NT 6.1 SP1,也就是Windows Vista)。 - Build info: 提供了Selenium WebDriver的版本(2.44.0),修订号(76d78cf)以及构建时间(2014-10-23 20:03:00)。 - System info: 描述了主机名、IP地址、操作系统详细信息以及Java版本(1.6.0_13)。 - SessionID: 这是一个唯一标识符,用于追踪特定的浏览器会话。 - Capabilities: 列出了浏览器的能力,包括接受SSL证书、启用JavaScript、浏览器名称(Chrome)、版本信息等。 解决这个错误的方法通常有以下几点: 1. **避免使用复合类名**:将CSS选择器改为只包含一个类名,或者使用其他选择器方法,如ID选择器、元素选择器等。 2. **使用XPath选择器**:XPath允许你更灵活地定位元素,包括可以处理复合类名的情况。 3. **更新Selenium和ChromeDriver**:确保你使用的是最新版本的Selenium WebDriver和对应的ChromeDriver,因为较新的版本可能已经修复了这个问题。 4. **检查代码**:确认在尝试定位元素时没有语法错误,如多余的空格或拼写错误。 5. **审查HTML结构**:确保HTML元素的类名是有效的,并且在页面上确实存在。 最后,当遇到此类异常时,查看服务器是否提供了堆栈跟踪信息也很重要,因为这可以帮助定位问题的具体位置。在本例中,警告提示服务器未提供堆栈跟踪信息,因此可能需要更深入地调查代码和测试环境来解决问题。

Traceback (most recent call last): File "C:\Users\jzhcc\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\common\driver_finder.py", line 42, in get_path path = SeleniumManager().driver_location(options) if path is None else path File "C:\Users\jzhcc\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\common\selenium_manager.py", line 96, in driver_location result = self.run(args) File "C:\Users\jzhcc\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\common\selenium_manager.py", line 121, in run raise WebDriverException(f"Unsuccessful command executed: {command}.\n{result}{stderr}") selenium.common.exceptions.WebDriverException: Message: Unsuccessful command executed: C:\Users\jzhcc\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\common\windows\selenium-manager.exe --browser chrome --output json. error sending request for url (https://chromedriver.storage.googleapis.com/LATEST_RELEASE_49): error trying to connect: dns error: 这是在主机名解析时通常出现的暂时错误,它意味着本地服务器没有从权威服务器上收到响应。 (os error 11002) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\jzhcc\Desktop\222.py", line 3, in <module> browser = webdriver.Chrome() File "C:\Users\jzhcc\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 47, in __init__ self.service.path = DriverFinder.get_path(self.service, self.options) File "C:\Users\jzhcc\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\common\driver_finder.py", line 44, in get_path raise NoSuchDriverException(f"Unable to obtain {service.path} using Selenium Manager; {err}") selenium.common.exceptions.NoSuchDriverException: Message: Unable to obtain chromedriver using Selenium Manager; Message: Unsuccessful command executed: C:\Users\jzhcc\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\common\windows\selenium-manager.exe --browser chrome --output json. error sending request for url (https://chromedriver.storage.googleapis.com/LATEST_RELEASE_49): error trying to connect: dns error: 这是在主机名解析时通常出现的暂时错误,它意味着本地服务器没有从权威服务器上收到响应。 (os error 11002) ; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location

2023-07-20 上传

C:\Users\31114> & C:/Users/31114/AppData/Local/Microsoft/WindowsApps/python3.8.exe c:/Users/31114/Untitled-1.py c:/Users/31114/Untitled-1.py:8: DeprecationWarning: executable_path has been deprecated, please pass in a Service object driver = webdriver.Chrome(executable_path=driver_path) Traceback (most recent call last): File "c:/Users/31114/Untitled-1.py", line 8, in <module> driver = webdriver.Chrome(executable_path=driver_path) File "C:\Users\31114\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\chrome\webdriver.py", line 84, in __init__ super().__init__( File "C:\Users\31114\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\chromium\webdriver.py", line 104, in __init__ super().__init__( File "C:\Users\31114\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\remote\webdriver.py", line 286, in __init__ self.start_session(capabilities, browser_profile) File "C:\Users\31114\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\remote\webdriver.py", line 378, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "C:\Users\31114\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\remote\webdriver.py", line 440, in execute self.error_handler.check_response(response) File "C:\Users\31114\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\remote\errorhandler.py", line 245, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary Stacktrace: Backtrace: GetHandleVerifier [0x00CAA813+48355] (No symbol) [0x00C3C4B1] (No symbol) [0x00B45358] (No symbol) [0x00B61A9E] (No symbol) [0x00B60579] (No symbol) [0x00B90C55] (No symbol) [0x00B9093C] (No symbol) [0x00B8A536] (No symbol) [0x00B682DC] (No symbol) [0x00B693DD] GetHandleVerifier [0x00F0AABD+2539405] GetHandleVerifier [0x00F4A78F+2800735] GetHandleVerifier [0x00F4456C+2775612] GetHandleVerifier [0x00D351E0+616112] (No symbol) [0x00C45F8C] (No symbol) [0x00C42328] (No symbol) [0x00C4240B] (No symbol) [0x00C34FF7] BaseThreadInitThunk [0x75AD7D59+25] RtlInitializeExceptionChain [0x77D3B74B+107] RtlClearBits [0x77D3B6CF+191]代码为此错误,更改

2023-06-03 上传
2023-07-08 上传

Traceback (most recent call last): File "D:\lianxi\venv\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start self.process = subprocess.Popen(cmd, env=self.env, File "D:\python\lib\subprocess.py", line 951, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "D:\python\lib\subprocess.py", line 1420, in _execute_child hp, ht, pid, tid = _winapi.CreateProcess(executable, args, FileNotFoundError: [WinError 2] 系统找不到指定的文件。 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "D:\lianxi\爬虫\test.py", line 3, in <module> driver = webdriver.Chrome() # 指定使用Chrome浏览器 File "D:\lianxi\venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__ self.service.start() File "D:\lianxi\venv\lib\site-packages\selenium\webdriver\common\service.py", line 79, in start raise WebDriverException( selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home Exception ignored in: <function Service.__del__ at 0x000001F6C43F7700> Traceback (most recent call last): File "D:\lianxi\venv\lib\site-packages\selenium\webdriver\common\service.py", line 173, in __del__ self.stop() File "D:\lianxi\venv\lib\site-packages\selenium\webdriver\common\service.py", line 145, in stop if self.process is None: AttributeError: 'Service' object has no attribute 'process'

2023-06-11 上传