Traceback (most recent call last): File "D:\pythonsthl\flaskProject\SeleniumTest\24Test111.py", line 42, in <module> img_label = driver.find_element('//*[@id="app"]/div[1]/div[2]/div[2]/div/form/div[3]/div[2]/img') File "D:\pythonsthl\flaskProject\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 740, in find_element return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"] File "D:\pythonsthl\flaskProject\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 346, in execute self.error_handler.check_response(response) File "D:\pythonsthl\flaskProject\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 245, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: invalid locator (Session info: chrome=115.0.5790.99) Stacktrace: Backtrace: GetHandleVerifier [0x00FAA813+48355] (No symbol) [0x00F3C4B1] (No symbol) [0x00E45358] (No symbol) [0x00E70A9F] (No symbol) [0x00E70B3B] (No symbol) [0x00E9E232] (No symbol) [0x00E8A784] (No symbol) [0x00E9C922] (No symbol) [0x00E8A536] (No symbol) [0x00E682DC] (No symbol) [0x00E693DD] GetHandleVerifier [0x0120AABD+2539405] GetHandleVerifier [0x0124A78F+2800735] GetHandleVerifier [0x0124456C+2775612] GetHandleVerifier [0x010351E0+616112] (No symbol) [0x00F45F8C] (No symbol) [0x00F42328] (No symbol) [0x00F4240B] (No symbol) [0x00F34FF7] BaseThreadInitThunk [0x76227D59+25] RtlInitializeExceptionChain [0x76F9B79B+107] RtlClearBits [0x76F9B71F+191] Process finished with exit code 1
时间: 2023-12-26 19:04:37 浏览: 442
Python3+selenium配置常见报错解决方案
5星 · 资源好评率100%
这个错误是由于您在`find_element`方法中的XPath表达式格式不正确导致的。请确保XPath表达式是准确且完整的。
在您的代码中,您应该使用`By.XPATH`作为`find_element`方法的第一个参数,并将XPath表达式作为第二个参数传递给它。同时,请确保XPath表达式是否正确,可以通过在浏览器的开发者工具中验证XPath表达式是否能够正确地定位到元素。
请尝试修改代码如下:
```python
img_label = driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div[2]/div[2]/div/form/div[3]/div[2]/img')
```
如果问题仍然存在,请检查XPath表达式是否正确,并确保您正在访问的页面上存在具有相应XPath的元素。
阅读全文