How to get text of an HTML-Element with Selenium/Node.js

Viewed 12237

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.

2 Answers

Try this instead if you are inside an async function:

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

console.log(element);
Related