首页 > 系统相关 >Linux上使用selenium报错:AttributeError: 'Service' object has no attribute 'process'

Linux上使用selenium报错:AttributeError: 'Service' object has no attribute 'process'

时间:2023-02-10 11:12:03浏览次数:50  
标签:webdriver object service Service process py selenium chromedriver 报错

Linux上使用selenium报错:AttributeError: 'Service' object has no attribute 'process'

​ Linux 上安装了谷歌浏览器及对应版本的浏览器驱动(chromedriver),执行如下代码:

from selenium.webdriver.chrome.service import Service
from selenium import webdriver

service = Service(executable_path="/home/admin/python/py/crawler/chromedriver_win32/chromedriver")
driver = webdriver.Chrome(service=service)

​ 报错:

Traceback (most recent call last):
  File "/home/admin/python/py/crawler/test.py", line 38, in <module>
    driver = get_driver()
  File "/home/admin/python/py/crawler/test.py", line 34, in get_driver
    return webdriver.Chrome(service=service, options=options)
  File "/usr/local/python3/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    super().__init__(
  File "/usr/local/python3/lib/python3.9/site-packages/selenium/webdriver/chromium/webdriver.py", line 103, in __init__
    self.service.start()
  File "/usr/local/python3/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 106, in start
    self.assert_process_still_running()
  File "/usr/local/python3/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 117, in assert_process_still_running
    return_code = self.process.poll()
AttributeError: 'Service' object has no attribute 'process'

​ 解决过程:

​ 首先检查路径浏览器驱动路径是否正确,确定路径没有写错,还是报错

​ 检查浏览器和驱动版本是否对应,执行google-chrome -version命令查看浏览器版本,执行chromedriver -version查看驱动版本;我执行查看驱动版本命令的时候发生如下报错:

bash: /usr/local/bin/chromedriver: 权限不够

​ 显示权限不够,可是我当前登录用户已经设置为 root 用户了,后面百度了一下可能是文件权限的问题;cd 到 chromedriver 目录下,执行chmod 777 chromedriver命令修改文件权限,然后再执行查看驱动版本命令就没有报错了

​ 由此想到AttributeError: 'Service' object has no attribute 'process'也可能是权限问题,所以修改代码指定路径(/home/admin/python/py/crawler/chromedriver_win32/chromedriver)下驱动的权限,然后再次执行,代码正常运行

标签:webdriver,object,service,Service,process,py,selenium,chromedriver,报错
From: https://www.cnblogs.com/Y-wee/p/17108247.html

相关文章