5

Unfortunately I did not find any existing solution for my problem on stackoverflow. So, can someone help.

I want to get the text of an html-element. I tried this:

var element = driver.findElement(webdriver.By.className("credits")).getText();

console.log(element);

Unfortunately this did not work so far.

3
  • 1
    Can yo post the html that you are trying to get the text from? Commented Aug 15, 2017 at 17:59
  • Set var element = driver.findElement(webdriver.By.className("credits")).innerHTML Commented Aug 15, 2017 at 17:59
  • just use await if you are an async function. Commented Jun 20, 2024 at 10:49

3 Answers 3

14

Someone posted an answer and deleted it seconds after it...thank you anyway:

For you information, this works fine for me:

var textPromise = driver.findElement(webdriver.By.className("credits")).getText();
textPromise.then((text) => {
  console.log(text);
});
Sign up to request clarification or add additional context in comments.

Comments

3

Try this instead if you are inside an async function:

var element = await driver.findElement(webdriver.By.className("credits")).getText();

console.log(element);

Comments

0

You have to be inside of async function and use await

let elementName = await this.driver.findElement(By.css(`.factoryListElementName`)).getText()

console.log(elementName)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.