webdriverio 将 getText 字符串设置为变量 [英] webdriverio Set getText string to variable

查看:36
本文介绍了webdriverio 将 getText 字符串设置为变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试使用 webdriverio 使用 getText 方法的内容实例化一个变量.

I'm currently trying to instantiate a variable with the contents of the getText method using webdriverio.

  a = String(browser.getText('.field_notice'));

当我尝试打印变量时,这是输出:

When I attempt to print the variable this is the output:

[对象对象]

感谢您的帮助!

推荐答案

browser.getText() 是一个异步调用,因此您需要提供一个回调来实例化您的变量.试试这个:

browser.getText() is an asynchronous call so you will need to provide a callback to instantiate your variable. Try this :

browser
    .getText('.field_notice').then(function(text) {
        a = text;
    });

可以在 Webdriverio 开发人员指南中找到类似的示例:http://webdriver.io/guide.html

A similar example can be found on the Webdriverio Developer Guide : http://webdriver.io/guide.html

此外,由于此方法返回一个字符串,因此无需将变量转换为字符串.请参阅 https://github.com/webdriverio/webdriverio/blob/master/lib/commands/getText.js

Also, there is no need to convert the variable to a string since this method returns a string. See https://github.com/webdriverio/webdriverio/blob/master/lib/commands/getText.js

这篇关于webdriverio 将 getText 字符串设置为变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆