Noob question here, how can I get and log text from an element? Selenium mocha.js. I've been searching for days now and I constantly get either pending promise or function name. I went through multiple solutions and I am desperate. Here's my current code:
const updatedTimeValue = async () => {
return driver.findElement(By.className("MuiTypography-root jss1141 MuiTypography-body1")).getText().then(function (text) {
console.log(text)});
}
updatedTimeValue();
console.log(updatedTimeValue());
FYI I am not a testing engineer, I've been only coding for a couple of weeks so there's a lot of stuff that I just don't get yet.
CodePudding user response:
i don't know if it help or not, because i'am beginner too. First of all we need to identify the element with help of any of the locators like id, class, name, xpath or css and then apply getText() method on it to get the text content of the element.this answer from this website
CodePudding user response:
To get the result, you would need to call then
on the promise.
And to log the output, you can do
updatedTimeValue().then(console.log);
Note that it is the same as
updatedTimeValue().then(result => console.log(result));