Browser

Element Attributes

Read and write DOM attributes directly on matched elements.

Read and write DOM attributes directly on matched elements.

GetAttribute (on a resolved GPALElement) returns the current value of a named attribute or property. WithAttribute names an attribute on the active selector, and the following SetAttribute(value) call writes it via element.setAttribute(attribute, value), replacing any existing value or adding the attribute if missing. GPALElement.SetAttribute provides the same write as a direct helper on an already-resolved element.

WARNING

SetAttribute is a low-level DOM write - it does not simulate typing, does not honor GPAL.WithTypingDelay, and does not fire input/change events on its own. For typing into form fields use SendString or FillInAppend/FillInInsert/FillInOverwrite instead. If the page needs to react to an attribute change, follow up with FireChangeEvent.

Examples

GPAL Fluent: High-level fluent C# API

//QuerySelector resolves a single GPALElement matching the CSS selector immediately, without needing an out parameter. GetAttribute reads a named attribute or property from that resolved element. WithAttribute names an attribute on the active selector, and the following SetAttribute(value) call writes it via element.setAttribute(attribute, value), replacing any existing value or adding the attribute if missing. GPALElement.SetAttribute provides the same write as a direct helper on an already-resolved element.

// Read an attribute from a resolved element GPAL.Browser .GoTo("https://example.com") .WithSelector("#profile") .GetElement(out var gPalElement); string username = gPalElement.GetAttribute("data-username"); // Write an attribute via the fluent selector GPAL.Browser .WithSelector("#submit") .WithAttribute("disabled") .SetAttribute("true"); // Write an attribute on an already-resolved element gPalElement.SetAttribute("disabled", "true");