user3508995
user3508995

Reputation: 187

In NodeJS selenium-webdriver, how do you get innerHTML of element

I've gone through: https://code.google.com/p/selenium/wiki/WebDriverJs and it doesn't have any information. So, can someone help.

I have

var element = driver.findElements(webdriver.By.id("something"))
console.log('text='+element.getAttribute("inner‌​HTML"));

But doesn't work. Most of the documentation appears to be for JAVA not nodeJS. If you come across a .getText() function, I'm pretty sure that is JAVA. I actually just want the text part innerText, opposed to innerHTML. But that might be asking too much.

Upvotes: 4

Views: 12306

Answers (2)

tylucaskelley
tylucaskelley

Reputation: 131

Per the webdriver.js docs:

var myElement = element(by.css('.myclass'));

myElement.getInnerHtml().then(function(html) {
    //do stuff with html here
});

Hope that helps! It's working for me using Node.js + Selenium / WebDriver, etc.

Upvotes: 6

Vladimir Lezhnin
Vladimir Lezhnin

Reputation: 131

You can check innerHTML like this:

driver.executeScript(function() {
    return document.querySelector('#something').innerHTML;
  }).then(function(innerHTML) {
   //check content here 
  });

Upvotes: 13

Related Questions