代码完整 但一直报的同类型错误

代码完整 但一直报的同类型错误

Error

Traceback (most recent call last):

Failure: builtins.tuple: (<class 'AttributeError'>, AttributeError("'TestTravel' object has no attribute 'dr'")


相关截图:

http://img1.sycdn.imooc.com//climg/60950a3709efbf4c18140185.jpg

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
好帮手慕燕燕 2021-05-07 19:28:23

同学,你好!错误信息提示没有dr属性,同学检查一下代码中哪里调用了dr,是否有定义或正确导入。如果还是无法解决可将代码粘贴到这里,便于老师定位问题。

祝:学习愉快!

  • 提问者 weixin_慕UI4589459 #1
    ​import unittest
    from selenium import webdriver
    from time import sleep


    class TestTravel(unittest.TestCase):
    # 初始化操作 打开浏览器&浏览器设置
    # 最终结束操作 关闭浏览器
    # 用例分为 登录、下单两个部分
    @classmethod
    def setUpClass(cls):
    cls.dr = webdriver.Chrome()
    cls.dr.maximize_window()
    cls.dr.implicitly_wait(10)
    cls.dr.get("http://django.t.mukewang.com/#/")

    def test_a_login(self):
    # 跳转至登录页
    el_mine = self.dr.find_element_by_xpath("//*[@id='app']/div[1]/div[5]/div[3]")
    el_mine.click()
    sleep(1)
    # 登录
    self.dr.find_element_by_xpath("//*[@id='app']/div[1]/form/div[1]/div[2]/div/input").send_keys("13500000001")
    self.dr.find_element_by_xpath("//*[@id='app']/div[1]/form/div[2]/div[2]/div/input").send_keys("Success@2020")
    self.dr.find_element_by_xpath("//*[@id='app']/div[1]/form/div[3]/button").click()
    sleep(1)
    self.dr.find_element_by_xpath("//*[@id='app']/div[1]/div[5]/div[1]").click()
    sleep(2)

    def test_b_order(self):
    # 下单操作
    self.dr.find_element_by_xpath("//*[@id='app']/div[1]/div[4]/div[2]/a[1]").click()
    sleep(1)
    self.dr.find_element_by_xpath("//*[@id='app']/div[1]/div[5]/div[2]/div[2]/a").click()
    self.dr.find_element_by_xpath("//*[@id='app']/div[1]/form/div[1]/div[1]/div[2]/div/input").send_keys(
    "2020-12-01")
    self.dr.find_element_by_xpath("//*[@id='app']/div[1]/form/div[4]/div/button").click()
    sleep(1)
    el = self.dr.find_element_by_xpath("//*[@id='app']/div[1]/form/div/div/button")
    self.dr.execute_script('arguments[0].click()', el)
    self.dr.find_element_by_xpath("/html/body/div[5]/div[3]/button[2]").click()
    sleep(2)

    @classmethod
    def tearDownClass(cls):
    cls.dr.quit()

    if __name__ == '__main__':
    unittest.main()


    2021-05-07 20:40:18
  • 同学,你好!老师这边使用同学提供的代码,运行程序没有问题

    http://img1.sycdn.imooc.com//climg/6095f1410949c11408240347.jpg

    同学提供的截图中涉及test_a_order用例,代码中并没有,同学再仔细检查一下程序的执行是否正确

    http://img1.sycdn.imooc.com//climg/6095ee9709f8f25615550179.jpg

    祝:学习愉快!

    2021-05-08 10:04:54
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师