简体   繁体   中英

Get HTML Source of WebElement in Selenium WebDriverJS

There is a similar question out there (an older one in Python) but this one has to do with JS. Testing using Selenium in a NodeJS, Mocha environment. What I'd like to do is click on a Bootstrap dropdown and check the HTML to look for changes. I've tried the following:

test.it('should click on all header links',
function() {
    var elem = driver.findElement(By.id('Profile'));
    console.log(elem.getAttribute('innerHTML'));
    console.log(elem.getInnerHtml());
});

Both calls return the same thing.

{ then: [Function: then],
  cancel: [Function: cancel],
  isPending: [Function: isPending] }

I plan to feed the HTML into cheerio so i can check for structure changes. Appreciate any help on this.

I was able to retrieve the HTML as a string by doing the following.

driver.findElement(By.id('Profile')).getAttribute("innerHTML").then(function(profile) {
    console.log(profile);
});

I got the inner HTML with:

  element.getAttribute('innerHTML').then(function (html) {          
                console.log(html)
            })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM