Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python ';dict';对象没有属性';驱动程序&x27;_Python_Mobile_Automation_Appium - Fatal编程技术网

Python ';dict';对象没有属性';驱动程序&x27;

Python ';dict';对象没有属性';驱动程序&x27;,python,mobile,automation,appium,Python,Mobile,Automation,Appium,我不熟悉web自动化和python,所以请理解我的问题对你们来说可能微不足道。我正在尝试使用Appium测试应用程序并按下屏幕上的按钮。使用我的最低知识,我在下面创建了一个测试用例,该测试用例就是为了这样做的,但是我得到一个错误“dict”对象没有属性“driver” from appium import webdriver import time def setUp(): self = dict( platformName = "Android",

我不熟悉web自动化和python,所以请理解我的问题对你们来说可能微不足道。我正在尝试使用Appium测试应用程序并按下屏幕上的按钮。使用我的最低知识,我在下面创建了一个测试用例,该测试用例就是为了这样做的,但是我得到一个错误“dict”对象没有属性“driver”

from appium import webdriver
import time

def setUp():
    self = dict(
        platformName = "Android",
        platformVersion = "10",
        deviceName= "name",
        app= "C:\\AppiumProjects\\app-debug.apk",
        automationName= "UiAutomator2",
        appActivity = ".activities.SplashScreenActivity",
        appPackage = 'genericsurveyapp2',
        noReset = True,
        
        )
        
    self.driver = webdriver.Remote('http://localhost:4723/wd/hub',self)
    time.sleep(2)
    time.sleep(2)
    self.el = self.driver.find_element_by_id("idacceptButton")
    time.sleep(2)
    self.el.click

setUp()

我想你对自己命名的配置选项字典感到困惑。 在类中工作时,
self
允许您使用“点表示法”引用类的变量和方法。但是,使用字典“点表示法”可以访问字典类的变量和方法,而不是字典的内容

对于如何解决此问题,您基本上有3个选项:

  • 使用字典符号向字典添加元素。我不建议这样做,因为您在同一个字典中存储了3种不同类型的内容:配置选项、驱动程序对象和页面元素
  • self['driver']=webdriver.Remote('http://localhost:4723/wd/hub",我自己)
    self['el']=self['driver']。通过id(“idacceptButton”)查找元素
    self['el']。单击()
    
  • driver
    el
    指定为函数本地上下文中的变量。如果您打算在安装后丢弃config、driver和page元素,这就是我要使用的解决方案
  • driver=webdriver.Remote('http://localhost:4723/wd/hub",我自己)
    el=驱动程序。通过id(“idacceptButton”)查找元素
    el.单击()
    
  • 重构代码以使用遵循页面对象模式的类。这可能是您想要做的,因为它符合appium测试最佳实践
  • 不要在变量声明中使用点(.)。请尝试以下操作:
    self\u driver=..