在Selenium WebDriverJS中获取WebElement的HTML源文件



有一个类似的问题(在Python中是一个较老的问题),但这个问题与JS有关。在NodeJS、Mocha环境中使用Selenium进行测试。我想做的是单击Bootstrap下拉菜单并检查HTML以查找更改。我尝试了以下方法:

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());
});

两个调用返回相同的东西。

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

我计划将HTML提供给cheerio,以便我可以检查结构更改。感谢您的帮助。

通过执行以下操作,我能够以字符串的形式检索HTML。

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

我得到了内部HTML:

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

最新更新