Nightwatch.js - Can't figure out how to pass a local variable into a URL parameter

拥有回忆 提交于 2019-12-20 04:57:08

问题


I have tried both options, but nothing seems to work:

var webNum = browser.getText('selector');
var urlGo = 'https://gotourl.com/' + webNum;
browser.url(urlGo);

or

var webNum = browser.getText('selector');
browser.url('https://gotourl.com/' + webNum);

Any ideas?


回答1:


.getText() is returning a WebElement JSON Object rather than string (the documentation on nightwatch api is misleading...)

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);
});

This way should works.



来源:https://stackoverflow.com/questions/44273543/nightwatch-js-cant-figure-out-how-to-pass-a-local-variable-into-a-url-paramet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!