org.openqa.selenium.devtools.v85.css.CSS Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of selenium-devtools-v85 Show documentation
Show all versions of selenium-devtools-v85 Show documentation
Selenium automates browsers. That's it! What you do with that power is entirely up to you.
package org.openqa.selenium.devtools.v85.css;
import org.openqa.selenium.Beta;
import org.openqa.selenium.devtools.Command;
import org.openqa.selenium.devtools.Event;
import org.openqa.selenium.devtools.ConverterFunctions;
import java.util.Map;
import java.util.LinkedHashMap;
import org.openqa.selenium.json.JsonInput;
/**
* This domain exposes CSS read/write operations. All CSS objects (stylesheets, rules, and styles)
* have an associated `id` used in subsequent operations on the related object. Each object type has
* a specific `id` structure, and those are not interchangeable between objects of different kinds.
* CSS objects can be loaded using the `get*ForNode()` calls (which accept a DOM node id). A client
* can also keep track of stylesheets via the `styleSheetAdded`/`styleSheetRemoved` events and
* subsequently load the required stylesheet contents using the `getStyleSheet[Text]()` methods.
*/
@Beta()
public class CSS {
/**
* Inserts a new rule with the given `ruleText` in a stylesheet with given `styleSheetId`, at the
* position specified by `location`.
*/
public static Command addRule(org.openqa.selenium.devtools.v85.css.model.StyleSheetId styleSheetId, java.lang.String ruleText, org.openqa.selenium.devtools.v85.css.model.SourceRange location) {
java.util.Objects.requireNonNull(styleSheetId, "styleSheetId is required");
java.util.Objects.requireNonNull(ruleText, "ruleText is required");
java.util.Objects.requireNonNull(location, "location is required");
LinkedHashMap params = new LinkedHashMap<>();
params.put("styleSheetId", styleSheetId);
params.put("ruleText", ruleText);
params.put("location", location);
return new Command<>("CSS.addRule", Map.copyOf(params), ConverterFunctions.map("rule", org.openqa.selenium.devtools.v85.css.model.CSSRule.class));
}
/**
* Returns all class names from specified stylesheet.
*/
public static Command> collectClassNames(org.openqa.selenium.devtools.v85.css.model.StyleSheetId styleSheetId) {
java.util.Objects.requireNonNull(styleSheetId, "styleSheetId is required");
LinkedHashMap params = new LinkedHashMap<>();
params.put("styleSheetId", styleSheetId);
return new Command<>("CSS.collectClassNames", Map.copyOf(params), ConverterFunctions.map("classNames", input -> input.readArray(java.lang.String.class)));
}
/**
* Creates a new special "via-inspector" stylesheet in the frame with given `frameId`.
*/
public static Command createStyleSheet(org.openqa.selenium.devtools.v85.page.model.FrameId frameId) {
java.util.Objects.requireNonNull(frameId, "frameId is required");
LinkedHashMap params = new LinkedHashMap<>();
params.put("frameId", frameId);
return new Command<>("CSS.createStyleSheet", Map.copyOf(params), ConverterFunctions.map("styleSheetId", org.openqa.selenium.devtools.v85.css.model.StyleSheetId.class));
}
/**
* Disables the CSS agent for the given page.
*/
public static Command disable() {
LinkedHashMap params = new LinkedHashMap<>();
return new Command<>("CSS.disable", Map.copyOf(params));
}
/**
* Enables the CSS agent for the given page. Clients should not assume that the CSS agent has been
* enabled until the result of this command is received.
*/
public static Command enable() {
LinkedHashMap params = new LinkedHashMap<>();
return new Command<>("CSS.enable", Map.copyOf(params));
}
/**
* Ensures that the given node will have specified pseudo-classes whenever its style is computed by
* the browser.
*/
public static Command forcePseudoState(org.openqa.selenium.devtools.v85.dom.model.NodeId nodeId, java.util.List forcedPseudoClasses) {
java.util.Objects.requireNonNull(nodeId, "nodeId is required");
java.util.Objects.requireNonNull(forcedPseudoClasses, "forcedPseudoClasses is required");
LinkedHashMap params = new LinkedHashMap<>();
params.put("nodeId", nodeId);
params.put("forcedPseudoClasses", forcedPseudoClasses);
return new Command<>("CSS.forcePseudoState", Map.copyOf(params));
}
public static class GetBackgroundColorsResponse {
private final java.util.Optional> backgroundColors;
private final java.util.Optional computedFontSize;
private final java.util.Optional computedFontWeight;
public GetBackgroundColorsResponse(java.util.Optional> backgroundColors, java.util.Optional computedFontSize, java.util.Optional computedFontWeight) {
this.backgroundColors = backgroundColors;
this.computedFontSize = computedFontSize;
this.computedFontWeight = computedFontWeight;
}
/**
* The range of background colors behind this element, if it contains any visible text. If no
* visible text is present, this will be undefined. In the case of a flat background color,
* this will consist of simply that color. In the case of a gradient, this will consist of each
* of the color stops. For anything more complicated, this will be an empty array. Images will
* be ignored (as if the image had failed to load).
*/
public java.util.Optional> getBackgroundColors() {
return backgroundColors;
}
/**
* The computed font size for this node, as a CSS computed value string (e.g. '12px').
*/
public java.util.Optional getComputedFontSize() {
return computedFontSize;
}
/**
* The computed font weight for this node, as a CSS computed value string (e.g. 'normal' or
* '100').
*/
public java.util.Optional getComputedFontWeight() {
return computedFontWeight;
}
private static GetBackgroundColorsResponse fromJson(JsonInput input) {
java.util.Optional> backgroundColors = java.util.Optional.empty();
java.util.Optional computedFontSize = java.util.Optional.empty();
java.util.Optional computedFontWeight = java.util.Optional.empty();
input.beginObject();
while (input.hasNext()) {
switch(input.nextName()) {
case "backgroundColors":
backgroundColors = java.util.Optional.ofNullable(input.readArray(java.lang.String.class));
break;
case "computedFontSize":
computedFontSize = java.util.Optional.ofNullable(input.nextString());
break;
case "computedFontWeight":
computedFontWeight = java.util.Optional.ofNullable(input.nextString());
break;
default:
input.skipValue();
break;
}
}
input.endObject();
return new GetBackgroundColorsResponse(backgroundColors, computedFontSize, computedFontWeight);
}
}
public static Command getBackgroundColors(org.openqa.selenium.devtools.v85.dom.model.NodeId nodeId) {
java.util.Objects.requireNonNull(nodeId, "nodeId is required");
LinkedHashMap params = new LinkedHashMap<>();
params.put("nodeId", nodeId);
return new Command<>("CSS.getBackgroundColors", Map.copyOf(params), input -> input.read(org.openqa.selenium.devtools.v85.css.CSS.GetBackgroundColorsResponse.class));
}
/**
* Returns the computed style for a DOM node identified by `nodeId`.
*/
public static Command> getComputedStyleForNode(org.openqa.selenium.devtools.v85.dom.model.NodeId nodeId) {
java.util.Objects.requireNonNull(nodeId, "nodeId is required");
LinkedHashMap params = new LinkedHashMap<>();
params.put("nodeId", nodeId);
return new Command<>("CSS.getComputedStyleForNode", Map.copyOf(params), ConverterFunctions.map("computedStyle", input -> input.readArray(org.openqa.selenium.devtools.v85.css.model.CSSComputedStyleProperty.class)));
}
public static class GetInlineStylesForNodeResponse {
private final java.util.Optional inlineStyle;
private final java.util.Optional attributesStyle;
public GetInlineStylesForNodeResponse(java.util.Optional inlineStyle, java.util.Optional attributesStyle) {
this.inlineStyle = inlineStyle;
this.attributesStyle = attributesStyle;
}
/**
* Inline style for the specified DOM node.
*/
public java.util.Optional getInlineStyle() {
return inlineStyle;
}
/**
* Attribute-defined element style (e.g. resulting from "width=20 height=100%").
*/
public java.util.Optional getAttributesStyle() {
return attributesStyle;
}
private static GetInlineStylesForNodeResponse fromJson(JsonInput input) {
java.util.Optional inlineStyle = java.util.Optional.empty();
java.util.Optional attributesStyle = java.util.Optional.empty();
input.beginObject();
while (input.hasNext()) {
switch(input.nextName()) {
case "inlineStyle":
inlineStyle = java.util.Optional.ofNullable(input.read(org.openqa.selenium.devtools.v85.css.model.CSSStyle.class));
break;
case "attributesStyle":
attributesStyle = java.util.Optional.ofNullable(input.read(org.openqa.selenium.devtools.v85.css.model.CSSStyle.class));
break;
default:
input.skipValue();
break;
}
}
input.endObject();
return new GetInlineStylesForNodeResponse(inlineStyle, attributesStyle);
}
}
/**
* Returns the styles defined inline (explicitly in the "style" attribute and implicitly, using DOM
* attributes) for a DOM node identified by `nodeId`.
*/
public static Command getInlineStylesForNode(org.openqa.selenium.devtools.v85.dom.model.NodeId nodeId) {
java.util.Objects.requireNonNull(nodeId, "nodeId is required");
LinkedHashMap params = new LinkedHashMap<>();
params.put("nodeId", nodeId);
return new Command<>("CSS.getInlineStylesForNode", Map.copyOf(params), input -> input.read(org.openqa.selenium.devtools.v85.css.CSS.GetInlineStylesForNodeResponse.class));
}
public static class GetMatchedStylesForNodeResponse {
private final java.util.Optional inlineStyle;
private final java.util.Optional attributesStyle;
private final java.util.Optional> matchedCSSRules;
private final java.util.Optional> pseudoElements;
private final java.util.Optional> inherited;
private final java.util.Optional> cssKeyframesRules;
public GetMatchedStylesForNodeResponse(java.util.Optional inlineStyle, java.util.Optional attributesStyle, java.util.Optional> matchedCSSRules, java.util.Optional> pseudoElements, java.util.Optional> inherited, java.util.Optional> cssKeyframesRules) {
this.inlineStyle = inlineStyle;
this.attributesStyle = attributesStyle;
this.matchedCSSRules = matchedCSSRules;
this.pseudoElements = pseudoElements;
this.inherited = inherited;
this.cssKeyframesRules = cssKeyframesRules;
}
/**
* Inline style for the specified DOM node.
*/
public java.util.Optional getInlineStyle() {
return inlineStyle;
}
/**
* Attribute-defined element style (e.g. resulting from "width=20 height=100%").
*/
public java.util.Optional getAttributesStyle() {
return attributesStyle;
}
/**
* CSS rules matching this node, from all applicable stylesheets.
*/
public java.util.Optional> getMatchedCSSRules() {
return matchedCSSRules;
}
/**
* Pseudo style matches for this node.
*/
public java.util.Optional> getPseudoElements() {
return pseudoElements;
}
/**
* A chain of inherited styles (from the immediate node parent up to the DOM tree root).
*/
public java.util.Optional> getInherited() {
return inherited;
}
/**
* A list of CSS keyframed animations matching this node.
*/
public java.util.Optional> getCssKeyframesRules() {
return cssKeyframesRules;
}
private static GetMatchedStylesForNodeResponse fromJson(JsonInput input) {
java.util.Optional inlineStyle = java.util.Optional.empty();
java.util.Optional attributesStyle = java.util.Optional.empty();
java.util.Optional> matchedCSSRules = java.util.Optional.empty();
java.util.Optional> pseudoElements = java.util.Optional.empty();
java.util.Optional> inherited = java.util.Optional.empty();
java.util.Optional> cssKeyframesRules = java.util.Optional.empty();
input.beginObject();
while (input.hasNext()) {
switch(input.nextName()) {
case "inlineStyle":
inlineStyle = java.util.Optional.ofNullable(input.read(org.openqa.selenium.devtools.v85.css.model.CSSStyle.class));
break;
case "attributesStyle":
attributesStyle = java.util.Optional.ofNullable(input.read(org.openqa.selenium.devtools.v85.css.model.CSSStyle.class));
break;
case "matchedCSSRules":
matchedCSSRules = java.util.Optional.ofNullable(input.readArray(org.openqa.selenium.devtools.v85.css.model.RuleMatch.class));
break;
case "pseudoElements":
pseudoElements = java.util.Optional.ofNullable(input.readArray(org.openqa.selenium.devtools.v85.css.model.PseudoElementMatches.class));
break;
case "inherited":
inherited = java.util.Optional.ofNullable(input.readArray(org.openqa.selenium.devtools.v85.css.model.InheritedStyleEntry.class));
break;
case "cssKeyframesRules":
cssKeyframesRules = java.util.Optional.ofNullable(input.readArray(org.openqa.selenium.devtools.v85.css.model.CSSKeyframesRule.class));
break;
default:
input.skipValue();
break;
}
}
input.endObject();
return new GetMatchedStylesForNodeResponse(inlineStyle, attributesStyle, matchedCSSRules, pseudoElements, inherited, cssKeyframesRules);
}
}
/**
* Returns requested styles for a DOM node identified by `nodeId`.
*/
public static Command getMatchedStylesForNode(org.openqa.selenium.devtools.v85.dom.model.NodeId nodeId) {
java.util.Objects.requireNonNull(nodeId, "nodeId is required");
LinkedHashMap params = new LinkedHashMap<>();
params.put("nodeId", nodeId);
return new Command<>("CSS.getMatchedStylesForNode", Map.copyOf(params), input -> input.read(org.openqa.selenium.devtools.v85.css.CSS.GetMatchedStylesForNodeResponse.class));
}
/**
* Returns all media queries parsed by the rendering engine.
*/
public static Command> getMediaQueries() {
LinkedHashMap params = new LinkedHashMap<>();
return new Command<>("CSS.getMediaQueries", Map.copyOf(params), ConverterFunctions.map("medias", input -> input.readArray(org.openqa.selenium.devtools.v85.css.model.CSSMedia.class)));
}
/**
* Requests information about platform fonts which we used to render child TextNodes in the given
* node.
*/
public static Command> getPlatformFontsForNode(org.openqa.selenium.devtools.v85.dom.model.NodeId nodeId) {
java.util.Objects.requireNonNull(nodeId, "nodeId is required");
LinkedHashMap params = new LinkedHashMap<>();
params.put("nodeId", nodeId);
return new Command<>("CSS.getPlatformFontsForNode", Map.copyOf(params), ConverterFunctions.map("fonts", input -> input.readArray(org.openqa.selenium.devtools.v85.css.model.PlatformFontUsage.class)));
}
/**
* Returns the current textual content for a stylesheet.
*/
public static Command getStyleSheetText(org.openqa.selenium.devtools.v85.css.model.StyleSheetId styleSheetId) {
java.util.Objects.requireNonNull(styleSheetId, "styleSheetId is required");
LinkedHashMap params = new LinkedHashMap<>();
params.put("styleSheetId", styleSheetId);
return new Command<>("CSS.getStyleSheetText", Map.copyOf(params), ConverterFunctions.map("text", java.lang.String.class));
}
/**
* Find a rule with the given active property for the given node and set the new value for this
* property
*/
public static Command setEffectivePropertyValueForNode(org.openqa.selenium.devtools.v85.dom.model.NodeId nodeId, java.lang.String propertyName, java.lang.String value) {
java.util.Objects.requireNonNull(nodeId, "nodeId is required");
java.util.Objects.requireNonNull(propertyName, "propertyName is required");
java.util.Objects.requireNonNull(value, "value is required");
LinkedHashMap params = new LinkedHashMap<>();
params.put("nodeId", nodeId);
params.put("propertyName", propertyName);
params.put("value", value);
return new Command<>("CSS.setEffectivePropertyValueForNode", Map.copyOf(params));
}
/**
* Modifies the keyframe rule key text.
*/
public static Command setKeyframeKey(org.openqa.selenium.devtools.v85.css.model.StyleSheetId styleSheetId, org.openqa.selenium.devtools.v85.css.model.SourceRange range, java.lang.String keyText) {
java.util.Objects.requireNonNull(styleSheetId, "styleSheetId is required");
java.util.Objects.requireNonNull(range, "range is required");
java.util.Objects.requireNonNull(keyText, "keyText is required");
LinkedHashMap params = new LinkedHashMap<>();
params.put("styleSheetId", styleSheetId);
params.put("range", range);
params.put("keyText", keyText);
return new Command<>("CSS.setKeyframeKey", Map.copyOf(params), ConverterFunctions.map("keyText", org.openqa.selenium.devtools.v85.css.model.Value.class));
}
/**
* Modifies the rule selector.
*/
public static Command setMediaText(org.openqa.selenium.devtools.v85.css.model.StyleSheetId styleSheetId, org.openqa.selenium.devtools.v85.css.model.SourceRange range, java.lang.String text) {
java.util.Objects.requireNonNull(styleSheetId, "styleSheetId is required");
java.util.Objects.requireNonNull(range, "range is required");
java.util.Objects.requireNonNull(text, "text is required");
LinkedHashMap params = new LinkedHashMap<>();
params.put("styleSheetId", styleSheetId);
params.put("range", range);
params.put("text", text);
return new Command<>("CSS.setMediaText", Map.copyOf(params), ConverterFunctions.map("media", org.openqa.selenium.devtools.v85.css.model.CSSMedia.class));
}
/**
* Modifies the rule selector.
*/
public static Command setRuleSelector(org.openqa.selenium.devtools.v85.css.model.StyleSheetId styleSheetId, org.openqa.selenium.devtools.v85.css.model.SourceRange range, java.lang.String selector) {
java.util.Objects.requireNonNull(styleSheetId, "styleSheetId is required");
java.util.Objects.requireNonNull(range, "range is required");
java.util.Objects.requireNonNull(selector, "selector is required");
LinkedHashMap params = new LinkedHashMap<>();
params.put("styleSheetId", styleSheetId);
params.put("range", range);
params.put("selector", selector);
return new Command<>("CSS.setRuleSelector", Map.copyOf(params), ConverterFunctions.map("selectorList", org.openqa.selenium.devtools.v85.css.model.SelectorList.class));
}
/**
* Sets the new stylesheet text.
*/
public static Command setStyleSheetText(org.openqa.selenium.devtools.v85.css.model.StyleSheetId styleSheetId, java.lang.String text) {
java.util.Objects.requireNonNull(styleSheetId, "styleSheetId is required");
java.util.Objects.requireNonNull(text, "text is required");
LinkedHashMap params = new LinkedHashMap<>();
params.put("styleSheetId", styleSheetId);
params.put("text", text);
return new Command<>("CSS.setStyleSheetText", Map.copyOf(params), ConverterFunctions.map("sourceMapURL", java.lang.String.class));
}
/**
* Applies specified style edits one after another in the given order.
*/
public static Command> setStyleTexts(java.util.List edits) {
java.util.Objects.requireNonNull(edits, "edits is required");
LinkedHashMap params = new LinkedHashMap<>();
params.put("edits", edits);
return new Command<>("CSS.setStyleTexts", Map.copyOf(params), ConverterFunctions.map("styles", input -> input.readArray(org.openqa.selenium.devtools.v85.css.model.CSSStyle.class)));
}
/**
* Enables the selector recording.
*/
public static Command startRuleUsageTracking() {
LinkedHashMap params = new LinkedHashMap<>();
return new Command<>("CSS.startRuleUsageTracking", Map.copyOf(params));
}
/**
* Stop tracking rule usage and return the list of rules that were used since last call to
* `takeCoverageDelta` (or since start of coverage instrumentation)
*/
public static Command> stopRuleUsageTracking() {
LinkedHashMap params = new LinkedHashMap<>();
return new Command<>("CSS.stopRuleUsageTracking", Map.copyOf(params), ConverterFunctions.map("ruleUsage", input -> input.readArray(org.openqa.selenium.devtools.v85.css.model.RuleUsage.class)));
}
public static class TakeCoverageDeltaResponse {
private final java.util.List coverage;
private final java.lang.Number timestamp;
public TakeCoverageDeltaResponse(java.util.List coverage, java.lang.Number timestamp) {
this.coverage = java.util.Objects.requireNonNull(coverage, "coverage is required");
this.timestamp = java.util.Objects.requireNonNull(timestamp, "timestamp is required");
}
public java.util.List getCoverage() {
return coverage;
}
/**
* Monotonically increasing time, in seconds.
*/
public java.lang.Number getTimestamp() {
return timestamp;
}
private static TakeCoverageDeltaResponse fromJson(JsonInput input) {
java.util.List coverage = null;
java.lang.Number timestamp = 0;
input.beginObject();
while (input.hasNext()) {
switch(input.nextName()) {
case "coverage":
coverage = input.readArray(org.openqa.selenium.devtools.v85.css.model.RuleUsage.class);
break;
case "timestamp":
timestamp = input.nextNumber();
break;
default:
input.skipValue();
break;
}
}
input.endObject();
return new TakeCoverageDeltaResponse(coverage, timestamp);
}
}
/**
* Obtain list of rules that became used since last call to this method (or since start of coverage
* instrumentation)
*/
public static Command takeCoverageDelta() {
LinkedHashMap params = new LinkedHashMap<>();
return new Command<>("CSS.takeCoverageDelta", Map.copyOf(params), input -> input.read(org.openqa.selenium.devtools.v85.css.CSS.TakeCoverageDeltaResponse.class));
}
public static Event fontsUpdated() {
return new Event<>("CSS.fontsUpdated", ConverterFunctions.map("font", org.openqa.selenium.devtools.v85.css.model.FontFace.class));
}
public static Event mediaQueryResultChanged() {
return new Event<>("CSS.mediaQueryResultChanged", ConverterFunctions.empty());
}
public static Event styleSheetAdded() {
return new Event<>("CSS.styleSheetAdded", ConverterFunctions.map("header", org.openqa.selenium.devtools.v85.css.model.CSSStyleSheetHeader.class));
}
public static Event styleSheetChanged() {
return new Event<>("CSS.styleSheetChanged", ConverterFunctions.map("styleSheetId", org.openqa.selenium.devtools.v85.css.model.StyleSheetId.class));
}
public static Event styleSheetRemoved() {
return new Event<>("CSS.styleSheetRemoved", ConverterFunctions.map("styleSheetId", org.openqa.selenium.devtools.v85.css.model.StyleSheetId.class));
}
}