简体   繁体   English

Python Selenium 异常 AttributeError:“'Service' object 在 selenium.webdriver.ie.service.Service 中没有属性'process'”

[英]Python Selenium Exception AttributeError: "'Service' object has no attribute 'process'" in selenium.webdriver.ie.service.Service

I have a Selenium Python test suite.我有一个 Selenium Python 测试套件。 It starts to run but after a few mins the following error is thrown:它开始运行,但几分钟后抛出以下错误:

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

My test suite implementation is:我的测试套件实现是:

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)

Can anyone help why this error is stopping my test suite from running?任何人都可以帮助解释为什么这个错误会阻止我的测试套件运行吗? How do I solve this?我该如何解决这个问题?

Provided you have installed selenium, and assuming that earlier in the console's traceback log you also got something like "'chromedriver' executable needs to be in PATH" in your script, you should be able to do: 如果你已经安装了selenium,并且假设在控制台的追溯日志中早些时候你的脚本中也有类似“'chromedriver'可执行文件需要在PATH中”,你应该可以这样做:

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

This should tell your script where to find chromedriver. 这应该告诉你的脚本在哪里可以找到chromedriver。 On a Mac you can usually use: /usr/local/bin/chromedriver 在Mac上,您通常可以使用:/ usr / local / bin / chromedriver

Download chromium driver from https://sites.google.com/a/chromium.org/chromedriver/downloads https://sites.google.com/a/chromium.org/chromedriver/downloads下载铬驱动程序

Unzip the file and then from your code, write something like: 解压缩文件,然后从代码中解压缩,如下所示:

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

where /path/to/chromedriver is the location of your chromedriver. 其中/ path / to / chromedriver是你的chromedriver的位置。

This is the class declaration for Chrome Webdriver: selenium.webdriver.chrome.webdriver.WebDriver(executable_path='chromedriver', ... 这是Chrome Webdriver的类声明: selenium.webdriver.chrome.webdriver.WebDriver(executable_path='chromedriver', ...

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

Given what @CubeBot88 had already written, another way to get the chromedriver executable in PATH is to do as follow:考虑到@CubeBot88 已经编写的内容,另一种chromedriver executable in PATH方法是执行以下操作:

from os
from selenium import webdriver 
os.environ['PATH'] += "/path/to/chromedriver"
driver = webdriver.Chrome()

The above way puts the path to chromedriver to environment variable PATH only in this program, allowing independent PATH in different situations.上述方式将chromedriver的路径放在本程序中只放在环境变量PATH中,允许在不同情况下使用独立的PATH

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError: 'Service' object 没有属性 'items' - Python Selenium - AttributeError: 'Service' object has no attribute 'items' - Python Selenium Selenium-“服务”对象没有属性“进程” - Selenium - 'Service' object has no attribute 'process' AttributeError:Selenium Webdriver中的python对象没有属性 - AttributeError: object has no attribute in python in selenium webdriver 使用python美丽的硒提取硒汤时,错误“服务”对象没有属性“过程” - Error 'Service' object has no attribute 'process' while using python beautiful soup extraction with selenium Selenium Webdriver Python AttributeError类型对象没有属性 - Selenium Webdriver Python AttributeError type object has no attribute AttributeError: 'WebDriver' object 在 selenium python 中没有属性 'send_keys' - AttributeError: 'WebDriver' object has no attribute 'send_keys' in selenium python 使用Python在Firefox中打开Webdriver时Selenium服务对象错误 - Selenium Service Object Error when opening Webdriver with Firefox in Python AttributeError:“ WebElement”对象没有属性(python)(硒) - AttributeError: 'WebElement' object has no attribute (python) (selenium) AttributeError: 'list' 对象没有属性 'click' - Selenium Webdriver - AttributeError: 'list' object has no attribute 'click' - Selenium Webdriver Python Selenium'WebDriver'对象没有属性错误 - Python Selenium 'WebDriver' object has no attribute error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM