2

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!

Dimi
  • 193
  • 1
  • 3
  • 13

2 Answers2

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

jrader
  • 670
  • 1
  • 5
  • 15
-1

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

Raghav N
  • 201
  • 1
  • 6