【问题标题】:AttributeError: 'unicode' object has no attribute '_current_application'AttributeError:“unicode”对象没有属性“_current_application”
【发布时间】:2016-01-05 20:50:05
【问题描述】:

我在 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'

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

【问题讨论】:

  • 嗯...没有self 因为你不在课堂上...!?
  • 我已经从函数的参数中删除了 self,但我仍然有相同的探针

标签: python appium python-appium


【解决方案1】:

PressKeyboardButton 是一个接受名为 self 的参数的函数,因为它会导致 unicode 对象出错,我假设您将 unicode 字符串作为参数传递给您的函数。 String 显然没有定义任何_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.

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

【讨论】:

    猜你喜欢
    • 2017-05-19
    • 2019-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-24
    • 2018-07-15
    相关资源
    最近更新 更多