Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用 Selenium 的 FluentAutomation 版本,但我找不到任何方法来获取元素的 HTML。我可以获取文本和属性,但似乎没有任何方法可以获取完整的 HTML 内容,这是我正在做的某种测试所需要的。
有没有办法做到这一点?
假设你的意思是innerHTML或outerHTML,你应该能够调用GetAttribute元素,或者你的语言中的任何内容。
GetAttribute
示例 C#:
element.GetAttribute("innerHTML");
示例红宝石:
element.attribute('innerHTML')
我不确定是否存在直接的方式,无论如何,应该可以执行类似于:
((JavascriptExecutor)driver).executeScript("return arguments[0].innerHTML;", element);