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.
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.
Share Improve this question edited Aug 16, 2017 at 5:54 NarendraR 7,70811 gold badges47 silver badges88 bronze badges asked Aug 15, 2017 at 17:37 TonisalTonisal 1911 gold badge1 silver badge6 bronze badges 3 |3 Answers
Reset to default 14Someone 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);
});
Try this instead if you are inside an async function:
var element = await driver.findElement(webdriver.By.className("credits")).getText();
console.log(element);
You have to be inside of async function and use await
let elementName = await this.driver.findElement(By.css(`.factoryListElementName`)).getText()
console.log(elementName)
var element = driver.findElement(webdriver.By.className("credits")).innerHTML
– Luke Danger Kozorosky Commented Aug 15, 2017 at 17:59await
if you are an async function. – Makan dianka Commented Jun 20, 2024 at 10:49