Python Selenium Exception AttributeError: "'Service' object has no attribute 'process'" in

Posted

技术标签:

【中文标题】Python Selenium Exception AttributeError: "\'Service\' object has no attribute \'process\'" in selenium.webdriver.ie.service.Service【英文标题】:Python Selenium Exception AttributeError: "'Service' object has no attribute 'process'" in selenium.webdriver.ie.service.ServicePython Selenium Exception AttributeError: "'Service' object has no attribute 'process'" in selenium.webdriver.ie.service.Service 【发布时间】:2016-08-28 12:40:46 【问题描述】:

我有一个 Selenium Python 测试套件。它开始运行,但几分钟后抛出以下错误:

Exception AttributeError: "'Service' object has no attribute 'process'" in <bound method Service.__del__ of <selenium.webdriver.ie.service.Service object at 0x0000000002610DD8>> ignored

我的测试套件实现是:

import unittest
from htmlTestRunner2 import HTMLTestRunner
import os
import Regression_TestCase.RegressionProject_TestCase2


# get the directory path to output report file
#result_dir = os.getcwd()
result_dir = r"E:\test_runners\selenium_regression_test_5_1_1\ClearCore - Regression Test\TestReport"

# get all tests from SearchProductTest and HomePageTest class
search_tests = unittest.TestLoader().loadTestsFromTestCase(Regression_TestCase.RegressionProject_TestCase2.RegressionProject_TestCase2)

# create a test suite combining search_test
re_tests = unittest.TestSuite([search_tests])

# open the report file
outfile = open(result_dir + "\TestReport.html", "w")

# configure HTMLTestRunner options
runner = HTMLTestRunner.HTMLTestRunner(stream=outfile,
                                       title='Test Report',
                                       description='Smoke Tests')

# run the suite using HTMLTestRunner
runner.run(re_tests)

谁能帮忙解释为什么这个错误会阻止我的测试套件运行?我该如何解决?

【问题讨论】:

【参考方案1】:

如果您已经安装了 selenium,并且假设在控制台的回溯日志中早些时候您的脚本中也有类似“'chromedriver' 可执行文件需要在 PATH 中”之类的内容,那么您应该能够做到:

from selenium import webdriver
driver = webdriver.Chrome("/path/to/chromedriver")

这应该告诉您的脚本在哪里可以找到 chromedriver。在 Mac 上,您通常可以使用:/usr/local/bin/chromedriver

【讨论】:

【参考方案2】:

从https://sites.google.com/a/chromium.org/chromedriver/downloads下载chromium驱动

解压缩文件,然后从您的代码中编写如下内容:

     from selenium import webdriver 
     driver = webdriver.Chrome("/path/to/chromedriver")

其中 /path/to/chromedriver 是您的 chromedriver 的位置。

这是 Chrome Webdriver 的类声明:selenium.webdriver.chrome.webdriver.WebDriver(executable_path='chromedriver', ...

取自https://seleniumhq.github.io/selenium/docs/api/py/webdriver_chrome/selenium.webdriver.chrome.webdriver.html#module-selenium.webdriver.chrome.webdriver

【讨论】:

是的,但仍然使用该代码,出现相同的错误:webdriver/chrome/webdriver.py", line 62, in __init__ self.service.start() Exception AttributeError: "'Service' object has no attribute 'process'" in &lt;bound method Service.__del__ of &lt;selenium.webdriver.chrome.service.Service object at 0x7f05180ff5d0&gt;&gt; ignored

以上是关于Python Selenium Exception AttributeError: "'Service' object has no attribute 'process'" in的主要内容,如果未能解决你的问题,请参考以下文章

ElementNotVisibleException:Python + Selenium,W eb上的登录凭据

selenium各种exception

selenium.common.exceptions.InvalidSessionIdException通过Python在无头模式下使用GeckoDriver Selenium Firefox(示例代

尝试使用Internet Explorer 11 / IE11运行Codeception / Selenium时的PHPUnit_Framework_Exception

selenium.common.exceptions.ElementNotVisibleException:消息:元素不可交互,显式等待不能使用Selenium和Python

尝试使用 Internet Explorer 11 / IE11 运行 Codeception / Selenium 时出现 PHPUnit_Framework_Exception