Python Selenium Exception AttributeError:“'service'对象在selenium.webdriver.ie.service.Service中没有属性'process'”

时间:2016-05-03 12:48:43

标签: python python-2.7 selenium selenium-webdriver

我有一个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)

任何人都可以帮助解决此错误导致我的测试套件无法运行的原因吗?我该如何解决这个问题?

2 个答案:

答案 0 :(得分:13)

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

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

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

答案 1 :(得分:2)

https://sites.google.com/a/chromium.org/chromedriver/downloads

下载铬驱动程序

解压缩文件,然后从代码中解压缩,如下所示:

     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