F:\ziliao\jiawei\pycharm\hello\001.py:13: DeprecationWarning: executable_path has been deprecated, please pass in a Service object driver = webdriver.Chrome(chrome_driver, options=options) Traceback (most recent call last): File "F:\ziliao\jiawei\pycharm\hello\001.py", line 24, in <module> aaa= driver.find_element(By.XPATH,'//input[@id="servNumber" and @name="gryBillItemVO.servNumber" and contains(@class, "mw") and contains(@class, "field") and contains(@class, "text")]') File "F:\ziliao\jiawei\pycharm\hello\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 831, in find_element return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"] File "F:\ziliao\jiawei\pycharm\hello\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 440, in execute self.error_handler.check_response(response) File "F:\ziliao\jiawei\pycharm\hello\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 245, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//input[@id="servNumber" and @name="gryBillItemVO.servNumber" and contains(@class, "mw") and contains(@class, "field") and contains(@class, "text")]"} (Session info: chrome=101.0.4951.41) Stacktrace:
时间: 2023-06-30 12:14:39 浏览: 141
网络通信安全:非授权接入控制.pptx
这个错误提示包含两个部分:
1. DeprecationWarning: executable_path has been deprecated, please pass in a Service object
这个警告是因为在创建ChromeDriver对象时使用了`executable_path`参数,而这个参数已经被废弃了。现在应该使用`Service`对象来指定ChromeDriver的路径。你可以参考下面的代码:
```
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
chrome_path = "path/to/chromedriver"
service = Service(chrome_path)
driver = webdriver.Chrome(service=service, options=options)
```
2. NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//input[@id="servNumber" and @name="gryBillItemVO.servNumber" and contains(@class, "mw") and contains(@class, "field") and contains(@class, "text")]"} (Session info: chrome=101.0.4951.41)
这个错误提示是因为无法定位到指定的元素。可能是因为XPath表达式不正确或者元素还没有加载出来。你可以尝试增加等待时间或者修改XPath表达式来定位到正确的元素。
阅读全文