简体   繁体   English

如何在 HtmlUnit 中请求 CSS 属性?

[英]How can I request a CSS attribut in HtmlUnit?

How can I request a CSS attribute like "display" from a HtmlElement in HtmlUnit?如何从 HtmlUnit 中的 HtmlElement 请求像“display”这样的 CSS 属性? The attribute is not set directly to the else over CSS classes of parent nodes.该属性不会直接设置为父节点的其他 CSS 类。

Try to use the following:尝试使用以下内容:

   WebClient webClient = new WebClient();
   XHtmlPage page = webClient.getPage("…");
   HtmlElement div = page.getHtmlElementById("elem_container");
   WebWindow window = webClient.getCurrentWindow();
   Window jscript = (Window) window.getScriptObject();
   HTMLElement element = (HTMLElement) jscript.makeScriptableFor(div);
   ComputedCSSStyleDeclaration style = jscript.jsxFunction_getComputedStyle(element, null);
   System.out.println(style);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM