Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:SeleniumHQ Selenium ScriptKey

From Leeroopedia
Knowledge Sources
Domains WebDriver, Browser_Automation
Last Updated 2026-02-12 00:00 GMT

Overview

Concrete tool for representing a unique identifier for a JavaScript script within Selenium's script pinning mechanism, provided by the Selenium WebDriver library.

Description

ScriptKey is a Java class in the org.openqa.selenium package that serves as an immutable identifier for a JavaScript script. It wraps a non-null String identifier and provides proper value-object semantics through equals() and hashCode() implementations based on the identifier value.

The class acts as the base type for script identification in Selenium's pinned-script infrastructure. It supports JSON serialization through a private toJson() method that returns the raw identifier string, and deserialization through a private static fromJson(String) factory method.

Key characteristics:

  • Immutable -- the identifier is set at construction time and cannot be changed.
  • Value semantics -- two ScriptKey instances with the same identifier are considered equal.
  • Non-null enforcement -- the constructor uses Require.nonNull to reject null identifiers.

Usage

Use ScriptKey as a handle to track and reference pinned scripts within the WebDriver session. It is typically not used directly by end users but rather as part of the script-pinning API:

  • Created when a script is pinned to a WebDriver session.
  • Used to reference or execute the pinned script later.
  • Extended by UnpinnedScriptKey for the full pinned-script lifecycle.

Code Reference

Source Location

Signature

public class ScriptKey {

    public ScriptKey(String identifier)
    public String getIdentifier()
    public boolean equals(Object o)
    public int hashCode()
}

Import

import org.openqa.selenium.ScriptKey;

I/O Contract

Constructor
Parameter Type Constraints Description
identifier String Non-null (enforced) Unique string identifier for the script
Methods
Method Input Output Description
getIdentifier() none String Returns the script's unique identifier
equals(Object o) Object (nullable) boolean Returns true if the other object is a ScriptKey with the same identifier
hashCode() none int Returns a hash code based on the identifier
JSON Serialization (private)
Method Direction Type Description
toJson() Serialize String Returns the raw identifier string for JSON output
fromJson(String) Deserialize ScriptKey Constructs a ScriptKey from a JSON identifier string

Usage Examples

// ScriptKey is typically created internally by the pinning mechanism
// Direct usage:
ScriptKey key = new ScriptKey("my-script-id-12345");
String id = key.getIdentifier(); // "my-script-id-12345"

// Value equality
ScriptKey key1 = new ScriptKey("abc");
ScriptKey key2 = new ScriptKey("abc");
boolean areEqual = key1.equals(key2); // true

// Use in collections (proper hashCode support)
Set<ScriptKey> scriptKeys = new HashSet<>();
scriptKeys.add(new ScriptKey("script-1"));
scriptKeys.add(new ScriptKey("script-2"));

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment