试验了下,果然是可以工作的哦~


def test_ui_computation(self):
        # populate text fields with values
        self._populate()
        # trigger computation by using the button
        buttons = self.driver.find_elements_by_tag_name("button")

        script = '''
            var target = UIATarget.localTarget();
            var app = target.frontMostApp();
            var window = app.mainWindow();
            buttons = window.buttons();
            buttons[0].tap();
            '''
        buttons = self.driver.execute_script(script); 

        # buttons[0].click()
        # is sum equal ?
        texts = self.driver.find_elements_by_tag_name("staticText")
        self.assertEqual(int(texts[0].text), self._values[0] + self._values[1])


@seveniruby


↙↙↙阅读原文可查看相关链接,并与作者交流