-1

I am automating the pressKeyButton() in python.for this following is the code

from AppiumLibrary import AppiumLibrary

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

After executing it, I have got the following exception:

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

can anybody suggest me solution.

oz123
  • 27,559
  • 27
  • 125
  • 187
sunil
  • 39
  • 1
  • 1
  • 5

1 Answers1

0

PressKeyboardButton is a function that is accept an argument named self, since it is causing error on unicode object, I'm assuming you are passing a unicode string as an argument to your function. String obviously doesn't have any _current_application attribute defined.

May be you are trying to use a class and mistaking function for a class, try something on these lines -

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.

Or you could just use a function

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.

Something on these lines, since it is not clear what you are trying to accomplish.

hspandher
  • 15,934
  • 2
  • 32
  • 45