简体   繁体   中英

Is there a way to get the HTML of an element?

I'm using the FluentAutomation version of Selenium, and I can't find any way to get the HTML of an element. I can get the text and attributes, but there doesn't seem to be any way to get the full HTML content, which I need for a certain kind of test I'm doing.

Is there any way to do this?

Assuming you mean the innerHTML or the outerHTML , you should just be able to call GetAttribute on the element, or whatever it is in your language.

Example C#:

element.GetAttribute("innerHTML");

Example Ruby:

element.attribute('innerHTML')

我不确定是否存在直接方法,无论如何,应该可以执行类似于以下内容的操作:

((JavascriptExecutor)driver).executeScript("return arguments[0].innerHTML;", element);

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