webdriverio Set getText string to variable

人走茶凉 提交于 2020-01-04 17:53:27

问题


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:

[object Object]

Thanks for the help!


回答1:


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

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

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




回答2:


Please use code something like below,

String textValue=driver.findElement(By.cssSelector("")).getText();

By.cssSelector("") is to find elements, you can use id or name or css based on the element defined in your page



来源:https://stackoverflow.com/questions/31353541/webdriverio-set-gettext-string-to-variable

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