Document doc = ???; HTMLDocument htmlDoc = (HTMLDocument)doc; final HTMLBodyElement body = (HTMLBodyElement)htmlDoc.getBody(); //JS [window] access DOMWindowImpl wnd = (DOMWindowImpl)((DocumentView)htmlDoc).getDefaultView(); //Style access CSSStyleDeclaration style = wnd.getComputedStyle(body, ""); assertEquals("Style extraction", "blue", style.getPropertyValue("background-color"));
public boolean isVisible() { return !(getElement().getStyle().getPropertyValue("display")).equals("none"); }
for (int propertyIndex = 0; propertyIndex < style.getLength(); propertyIndex++) { String propertyName = style.item(propertyIndex); String propertyValue = style.getPropertyValue(propertyName); elementStyles.put(propertyName, propertyValue);
private static void mergeAttribute(final DataFieldMeta meta, final HTMLElement beanElement, final HTMLElement templateElement, final String name, final String value) { final ConflictStrategy strategy = meta.getStrategy(name); // Merge all class names regardless of strategy if (name.equals("class")) { DOMUtil.tokenStream(templateElement.getClassList()) .filter(token -> !beanElement.getClassList().contains(token)) .forEach(token -> beanElement.getClassList().add(token)); } // Merge individual properties in style only using the strategy when both elements have a value. else if (name.equals("style")) { Stream<String> propertyNameStream = DOMUtil.cssPropertyNameStream(templateElement.getStyle()); if (ConflictStrategy.USE_BEAN.equals(strategy)) { propertyNameStream = propertyNameStream .filter(propertyName -> { final String beanPropertyValue = beanElement.getStyle().getPropertyValue(propertyName); return beanPropertyValue == null || beanPropertyValue.isEmpty(); }); } propertyNameStream .forEach(propertyName -> beanElement.getStyle().setProperty(propertyName, templateElement.getStyle().getPropertyValue(propertyName), "")); } // Use strategy to decide which value is used. else { final String beanValue = beanElement.getAttribute(name); if (ConflictStrategy.USE_TEMPLATE.equals(strategy) || beanValue == null || beanValue.isEmpty()) { beanElement.setAttribute(name, value); } } }
private static void mergeAttribute(final DataFieldMeta meta, final HTMLElement beanElement, final HTMLElement templateElement, final String name, final String value) { final ConflictStrategy strategy = meta.getStrategy(name); // Merge all class names regardless of strategy if (name.equals("class")) { DOMUtil.tokenStream(templateElement.getClassList()) .filter(token -> !beanElement.getClassList().contains(token)) .forEach(token -> beanElement.getClassList().add(token)); } // Merge individual properties in style only using the strategy when both elements have a value. else if (name.equals("style")) { Stream<String> propertyNameStream = DOMUtil.cssPropertyNameStream(templateElement.getStyle()); if (ConflictStrategy.USE_BEAN.equals(strategy)) { propertyNameStream = propertyNameStream .filter(propertyName -> { final String beanPropertyValue = beanElement.getStyle().getPropertyValue(propertyName); return beanPropertyValue == null || beanPropertyValue.isEmpty(); }); } propertyNameStream .forEach(propertyName -> beanElement.getStyle().setProperty(propertyName, templateElement.getStyle().getPropertyValue(propertyName), "")); } // Use strategy to decide which value is used. else { final String beanValue = beanElement.getAttribute(name); if (ConflictStrategy.USE_TEMPLATE.equals(strategy) || beanValue == null || beanValue.isEmpty()) { beanElement.setAttribute(name, value); } } }