AttributeError:' unicode'对象没有属性' _current_application'

时间:2015-10-08 09:49:37

标签: python appium python-appium

我正在python中自动化pressKeyButton()。以下是代码

from AppiumLibrary import AppiumLibrary

def PressKeyboardButton(self, buttonToPress):
    self._current_application().execute_script("var vKeyboard = target.frontMostApp().keyboard(); vKeyboard.buttons()['" + buttonToPress + "'].tap();");

执行后,我遇到以下异常:

AttributeError: 'unicode' object has no attribute '_current_application'

任何人都可以建议我解决。

1 个答案:

答案 0 :(得分:0)

PressKeyboardButton是一个接受名为self的参数的函数,因为它在unicode对象上引起错误,我假设您将一个unicode字符串作为参数传递给你的功能。字符串显然没有定义任何_current_application属性。

可能是您正在尝试使用类和错误函数来创建类,尝试使用这些行 -

class KeyboardButton:

      def press(self, button):
          self._current_application().execute_script("var vKeyboard = target.frontMostApp().keyboard(); vKeyboard.buttons()['" + buttonToPress + "'].tap();");

      def _current_application(self):
          # add your code.

或者您可以使用功能

from AppiumLibrary import AppiumLibrary

def PressKeyboardButton(self, buttonToPress):
    current_application().execute_script("var vKeyboard = target.frontMostApp().keyboard(); vKeyboard.buttons()['" + buttonToPress + "'].tap();")

def current_application():
    # your code.

这些方面的东西,因为你不清楚你想要完成什么。

相关问题