测试人社区

【求助】获取混合APP,H5页面的文本时,总显示为None

用老师上课教的APPUI测试框架去获取H5页面的文本时,总显示为None。
H5页面元素:

main.yaml文件里的写法:

outflow:
  - by: class name
    locator: "zljl-type"
    action: text

调用的写法:

class Test001():
    app = App()
    main = app.start().main()
    def test001(self):

        App().start().main().goto_market()
        sleep(6)
        self.app.swipe_window('up')
        # 打印所有的context
        contexts = self.app._driver.contexts
        print(contexts)
        # 切换到指定的webview
        self.app._driver.switch_to.context(contexts[-1])
        sleep(1)
        outflow = self.app.main().outflow()
        print(outflow)

打印出来是None。想问下老师这个为什么获取不到这个元素原本的文本,要怎么写才能获取到真实的文本信息

outflow()内容是什么啊?

outflow是这样写的:

 def outflow(self):
        self.steps("../data/main.yaml")

方法是这样写的:

 def steps(self, path):
        with open(path, encoding="utf-8") as f:
            name = inspect.stack()[1].function
            # 对yaml文件进行解析,取出跟name对应的value
            steps = yaml.safe_load(f)[name]
        # element = None
        raw = json.dumps(steps)
        for key, value in self._params.items():
            raw = raw.replace(f'${{{key}}}', value)
        steps = json.loads(raw)
        # 遍历steps(yaml文件内容)
        for step in steps:
            # 查找元素
            # if "by" in step.keys():
            #     element = self.find(step["by"], step["locator"])
            # 多个动作解析
            if "action" in step.keys():
                action = step["action"]
                if action == "click":
                    self.find(step["by"], step["locator"]).click()
                if action == "send":
                    # value = step["value"]
                    # print(f"send{value}")
                    self.find(step["by"], step["locator"]).send_keys(step["value"])
                if action == "len > 0":
                    eles = self.finds(step["by"], step["locator"])
                    return len(eles) > 0
                if action == "text":
                    text = self.find(step["by"], step["locator"]).text
                    return text

outflow()没有返回值啊,所以打印出来的是none

但是从上面的元素页面看,这个元素里是有text值的啊,所以要怎么获取到这个text值呢?

你的steps()有返回值但是outflow()没有返回值

def outflow(self):
        res  = self.steps("../data/main.yaml")
        return res

这样outflow()才有返回值

哇,可以了,谢谢老师