Nightwatch.js - 无法弄清楚如何将局部变量传递给URL参数 [英] Nightwatch.js - Can't figure out how to pass a local variable into a URL parameter
本文介绍了Nightwatch.js - 无法弄清楚如何将局部变量传递给URL参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已尝试过这两个选项,但似乎没有任何效果:
I have tried both options, but nothing seems to work:
var webNum = browser.getText('selector');
var urlGo = 'https://gotourl.com/' + webNum;
browser.url(urlGo);
或
var webNum = browser.getText('selector');
browser.url('https://gotourl.com/' + webNum);
任何想法?
推荐答案
.getText()返回 WebElement JSON对象
而不是字符串(关于nightwatch api的文档有误导性......)
.getText() is returning a WebElement JSON Object
rather than string (the documentation on nightwatch api is misleading...)
您想要的文本是 WebElement JSON对象
的值,您可以使用访问它。价值
The text you want is the value of the WebElement JSON Object
, and you can access it by using .value
如果您想获得以下文字:
if you would like to get the text you have to do the following :
var webNum = 'nothing';
browser.getText('selector',function(text){
webNum=text.value;
var urlGo = 'https://gotourl.com/' + webNum;
browser.url(urlGo);
});
这种方式应该有效。
这篇关于Nightwatch.js - 无法弄清楚如何将局部变量传递给URL参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文