selenium.webdriver.common._bidi.serialization#

Serialization runtime for the generated WebDriver BiDi protocol layer.

Hand-written support for the generated selenium.webdriver.common._bidi.* modules (not itself generated). Provides the immutable value-type base (Record), the discriminated-union dispatch base (Union), and the UNSET sentinel that distinguishes an omitted optional from an explicit wire null.

Each generated field carries its wire facts as dataclass field metadata (see meta()), so a record’s Python fields are its single source of truth — there is no parallel field table.

This is internal, unsupported implementation. See https://www.selenium.dev/documentation/warnings/bidi-implementation/

Module Attributes

UNSET

Marks an omitted optional.

Functions

meta(name, *[, required, nullable, ref, ...])

Dataclass field metadata carrying one field's BiDi wire facts.

register(schema_name)

Class decorator registering a generated class under its schema type name.

resolve(schema_name)

Classes

Record()

Immutable value-type base for generated params/results/event payloads.

Union()

Dispatch base for a discriminated union; subclassed, never instantiated.

UnsetType()

Type of the UNSET sentinel (an omitted optional, not None).

Exceptions

BiDiSerializationError([msg, screen, stacktrace])

A payload could not be (de)serialized against this Selenium's BiDi schema.

exception BiDiSerializationError(msg=None, screen=None, stacktrace=None)[source]#

Bases: WebDriverException

A payload could not be (de)serialized against this Selenium’s BiDi schema.

Parameters:
  • msg (Any | None)

  • screen (str | None)

  • stacktrace (Sequence[str] | None)

Return type:

None

args#
with_traceback()#

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class UnsetType[source]#

Bases: object

Type of the UNSET sentinel (an omitted optional, not None).

Return type:

UnsetType

UNSET: UnsetType = UNSET#

Marks an omitted optional. Dropped from the wire; distinct from None (explicit null).

meta(name, *, required=False, nullable=False, ref=None, is_list=False, enum=None, primitive=None, scalar=None, fixed=UNSET)[source]#

Dataclass field metadata carrying one field’s BiDi wire facts.

Used as x: T = field(metadata=meta(...)) in the generated modules — a plain dataclasses.field so it reads as an ordinary dataclass field. A baked discriminator additionally sets default=<const>, init=False on the field.

scalar marks a map field (a [key, value] list whose value type is an object-only union): the union’s string keys pass through when they match this primitive, rather than being rejected as non-objects.

Parameters:
  • name (str)

  • required (bool)

  • nullable (bool)

  • ref (str | None)

  • is_list (bool)

  • enum (str | None)

  • primitive (str | None)

  • scalar (str | list[str] | None)

  • fixed (Any)

Return type:

dict

register(schema_name)[source]#

Class decorator registering a generated class under its schema type name.

Parameters:

schema_name (str)

Return type:

Callable[[type], type]

resolve(schema_name)[source]#
Parameters:

schema_name (str)

Return type:

type

class Record[source]#

Bases: object

Immutable value-type base for generated params/results/event payloads.

Subclasses are @dataclass(frozen=True) whose fields are declared with meta(). The object itself is permissive; validation lives at the boundaries. Outbound (as_json()) omits UNSET, emits null only for nullable fields, and errors if a required field is unset. Inbound (from_json()) errors on a corrupt value or a missing required field, and tolerates only an undeclared property, so a browser that adds a field does not break a client generated from an older schema.

as_json()[source]#
Return type:

dict

classmethod from_json(payload)[source]#
Parameters:

payload (dict)

Return type:

Any

class Union[source]#

Bases: object

Dispatch base for a discriminated union; subclassed, never instantiated.

Carries the schema’s authoritative selector as class attributes: a discriminator wire key + tag->variant table, and/or presence-ordered rules, and an optional declared fallback. Inbound (from_json()) resolves a payload to a variant; outbound (build()) selects the variant a command’s kwargs describe.

classmethod validate_outbound(owner, name, value)[source]#

Reject an outbound value that is not one of this union’s variants.

A variant instance passes. A bare scalar passes only for a union that has a scalar arm, and only as one of the literals that arm declares, so a stray string is a caller error rather than a wire round-trip. This mirrors inbound dispatch, which errors on the same values.

Parameters:
  • owner (str)

  • name (str)

  • value (Any)

Return type:

None

classmethod from_json(payload)[source]#
Parameters:

payload (Any)

Return type:

Any

classmethod build(**kwargs)[source]#
Parameters:

kwargs (Any)

Return type:

Any