最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Get HTML Source of WebElement in Selenium WebDriverJS - Stack Overflow

programmeradmin6浏览0评论

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.

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.

Share Improve this question asked Jun 18, 2014 at 19:01 quikbeamquikbeam 3391 gold badge4 silver badges12 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

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)
            })
发布评论

评论列表(0)

  1. 暂无评论