Search code examples
pythonappium

can't click the button in appium but some others is okay


I am just new in python and encounter a problem in writing a test case.

Actually I've tried to use find_element with xpath in Appium but it reports timeout, then I use the coordinate method and try to click the button but still fail. It is strange that some of my button can be clicked.

Below is my code:

    self.action2 = TouchAction(self.driver)

    i = 0
    while i < 10:
            self.driver.swipe(x / 2, y * 9/10, x / 2, y * 5/100)
            time.sleep(1)
            i += 1

    self.action2.move_to(700,2620).tap().perform()

I expect the cursor should move to the (x offset, y offset)but it failed.

Here is the log:

>       self.user_login(username, password)
>       self.action2.move_to(700,2620).tap().perform()
C:\learnPython\lib\site-packages\appium\webdriver\common\touch_action.py:115: in move_to

>       self._add_action('moveTo', self._get_opts(el, x, y))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <appium.webdriver.common.touch_action.TouchAction object at 0x00000241EC651358>
element = 700, x = 2620, y = None, duration = None, pressure = None

>     def _get_opts(self, element, x, y, duration=None, pressure=None):
        opts = {}
        if element is not None:
>           opts['element'] = element.id
E           AttributeError: 'int' object has no attribute 'id'

C:\learnPython\lib\site-packages\appium\webdriver\common\touch_action.py:160: AttributeError


Solution

  • I looked at the source code of appium, I can see that move_to gets 3 parameters https://github.com/appium/python-client/blob/master/appium/webdriver/common/touch_action.py#L104

    So in your case you set the element parameter to 700, thats why there is an error.

    You can try either

    self.action2.move_to(x=700,y=2620).tap().perform()
    

    or

    self.action2.move_to(None,700,2620).tap().perform()