gpt4 book ai didi

javascript - 在 Selenium WebDriverJS 中获取 WebElement 的 HTML 源代码

转载 作者:行者123 更新时间:2023-11-29 10:14:57 25 4
gpt4 key购买 nike

那里有一个类似的问题(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);
});

关于javascript - 在 Selenium WebDriverJS 中获取 WebElement 的 HTML 源代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24293189/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com