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.
Coworker helped me and we got it working! I've also changed classname to XPath, but it shouldn't make a difference.
await driver.wait(until.elementLocated(By.xpath("/html/body/div[5]/div[3]/div/div/div[2]/div[1]/div[3]/div/div/div[1]/div/div[1]/div[1]/p[2]/span")));
const initialTimeValue = () => driver.findElement(By.xpath("/html/body/div[5]/div[3]/div/div/div[2]/div[1]/div[3]/div/div/div[1]/div/div[1]/div[1]/p[2]/span")).getText();
await console.log(initialTimeValue().then(console.log));
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments