社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

AttributeError:“GoogleSearch”对象在通过Python unittest执行测试时没有属性“driver”

Александр ВолкоР• 5 年前 • 1916 次点击  

我用这个帖子 http://www.autotest.org.ua/first-autotest-with-selenium-webdriver-and-python/ 在皮查姆做项目

This is a photo

代码测试:

from selenium import webdriver
import unittest
from selenium.webdriver.common.keys import Keys


class GoogleSearch(unittest.TestCase):
    def setUpp(self):
        self.driver = webdriver.Chrome(executable_path="C:\Python37-32\geckodriver-v0.23.0-win64\geckodriver.exe")
        self.driver.get('https://www.google.by')
        self.driver.maximize_window()
        self.driver.implicitly_wait(10)

    def test_01(self):
        driver = self.driver
        input_field = driver.find_element_by_class_name('class="gLFyf gsfi"')
        input_field.send_keys('python')
        input_field.send_keys(Keys.ENTER)

错误:

FAILED (errors=1)

Error
Traceback (most recent call last):
  File "C:\Python37-32\lib\unittest\case.py", line 59, in testPartExecutor
    yield
  File "C:\Python37-32\lib\unittest\case.py", line 615, in run
    testMethod()
  File "D:\QA\untitled\test.py", line 13, in test_01
    driver = self.driver
AttributeError: 'GoogleSearch' object has no attribute 'driver'


Process finished with exit code 1

我不知道怎么解决。。。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/50047
 
1916 次点击  
文章 [ 1 ]  |  最新文章 5 年前