dom

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 10, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertSimpleXpathToCssSelector

func ConvertSimpleXpathToCssSelector(xpath string) string

func EnhancedCssSelectorForElement

func EnhancedCssSelectorForElement(element *DOMElementNode, includeDynamicAttributes bool) string

Types

type ClickableElementProcessor

type ClickableElementProcessor struct {
}

func (*ClickableElementProcessor) GetClickableElements

func (c *ClickableElementProcessor) GetClickableElements(node *DOMElementNode) []*DOMElementNode

func (*ClickableElementProcessor) GetClickableElementsHashes

func (c *ClickableElementProcessor) GetClickableElementsHashes(node *DOMElementNode) []string

func (*ClickableElementProcessor) HashDomElement

func (c *ClickableElementProcessor) HashDomElement(domElement *DOMElementNode) string

type CoordinateSet

type CoordinateSet struct {
	TopLeft     Coordinates `json:"topLeft"`
	TopRight    Coordinates `json:"topRight"`
	BottomLeft  Coordinates `json:"bottomLeft"`
	BottomRight Coordinates `json:"bottomRight"`
	Center      Coordinates `json:"center"`
	Width       int         `json:"width"`
	Height      int         `json:"height"`
}

func (*CoordinateSet) ToDict

func (c *CoordinateSet) ToDict() map[string]any

type Coordinates

type Coordinates struct {
	X int `json:"x"`
	Y int `json:"y"`
}

func (*Coordinates) ToDict

func (c *Coordinates) ToDict() map[string]int

type DOMBaseNode

type DOMBaseNode interface {
	ToJson() map[string]any
	SetParent(parent *DOMElementNode)
}

Base interface for all DOM nodes

type DOMElementNode

type DOMElementNode struct {
	TagName             string            `json:"tagName"`
	Xpath               string            `json:"xpath"`
	Attributes          map[string]string `json:"attributes"`
	Children            []DOMBaseNode     `json:"children"`
	IsInteractive       bool              `json:"isInteractive"`
	IsTopElement        bool              `json:"isTopElement"`
	IsInViewport        bool              `json:"isInViewport"`
	ShadowRoot          bool              `json:"shadowRoot"`
	HighlightIndex      *int              `json:"highlightIndex,omitempty"`
	ViewportCoordinates *CoordinateSet    `json:"viewportCoordinates"`
	PageCoordinates     *CoordinateSet    `json:"pageCoordinates"`
	ViewportInfo        *ViewportInfo     `json:"viewportInfo"`
	Parent              *DOMElementNode   `json:"parent"`
	IsVisible           bool              `json:"isVisible"`
	IsNew               *bool             `json:"isNew,omitempty"`
}

DOMElementNode

func (*DOMElementNode) ClickableElementsToString

func (n *DOMElementNode) ClickableElementsToString(includeAttributes []string) string

func (*DOMElementNode) GetAllTextTillNextClickableElement

func (n *DOMElementNode) GetAllTextTillNextClickableElement(maxDepth int) string

func (*DOMElementNode) GetFileUploadElement

func (n *DOMElementNode) GetFileUploadElement(checkSiblings bool) *DOMElementNode

func (*DOMElementNode) Hash

func (n *DOMElementNode) Hash() HashedDomElement

func (*DOMElementNode) SetParent

func (n *DOMElementNode) SetParent(parent *DOMElementNode)

func (*DOMElementNode) ToJson

func (n *DOMElementNode) ToJson() map[string]any

func (*DOMElementNode) ToString

func (n *DOMElementNode) ToString() string

type DOMHistoryElement

type DOMHistoryElement struct {
	TagName                string            `json:"tagName"`
	Xpath                  string            `json:"xpath"`
	HighlightIndex         *int              `json:"highlightIndex,omitempty"`
	EntireParentBranchPath []string          `json:"entireParentBranchPath"`
	Attributes             map[string]string `json:"attributes"`
	ShadowRoot             bool              `json:"shadowRoot"`
	CssSelector            *string           `json:"cssSelector,omitempty"`
	PageCoordinates        *CoordinateSet    `json:"pageCoordinates"`
	ViewportCoordinates    *CoordinateSet    `json:"viewportCoordinates"`
	ViewportInfo           *ViewportInfo     `json:"viewportInfo"`
}

func (*DOMHistoryElement) ToDict

func (e *DOMHistoryElement) ToDict() map[string]any

type DOMState

type DOMState struct {
	ElementTree *DOMElementNode `json:"elementTree"`
	SelectorMap *SelectorMap    `json:"selectorMap"`
}

type DOMTextNode

type DOMTextNode struct {
	Text      string          `json:"text"`
	Type      string          `json:"type"` // default: TEXT_NODE
	Parent    *DOMElementNode `json:"parent"`
	IsVisible bool            `json:"isVisible"`
}

DOMTextNode

func (*DOMTextNode) HasParentWithHighlightIndex

func (n *DOMTextNode) HasParentWithHighlightIndex() bool

func (*DOMTextNode) IsParentInViewport

func (n *DOMTextNode) IsParentInViewport() bool

func (*DOMTextNode) IsParentTopElement

func (n *DOMTextNode) IsParentTopElement() bool

func (*DOMTextNode) SetParent

func (n *DOMTextNode) SetParent(parent *DOMElementNode)

func (*DOMTextNode) ToJson

func (n *DOMTextNode) ToJson() map[string]any

type DomService

type DomService struct {
	Page       playwright.Page `json:"page"`
	XpathCache map[string]any  `json:"xpathCache"`
	JsCode     string          `json:"jsCode"`
}

func NewDomService

func NewDomService(page playwright.Page) *DomService

func (*DomService) GetClickableElements

func (s *DomService) GetClickableElements(highlightElements bool, focusElement int, viewportExpansion int) (*DOMState, error)

func (*DomService) GetCrossOriginIframes

func (s *DomService) GetCrossOriginIframes() []string

type ElementTreeSerializer

type ElementTreeSerializer struct{}

Serialization helpers

func (ElementTreeSerializer) DomElementNodeToJson

func (ElementTreeSerializer) DomElementNodeToJson(elementTree *DOMElementNode) map[string]interface{}

func (ElementTreeSerializer) SerializeClickableElements

func (ElementTreeSerializer) SerializeClickableElements(elementTree *DOMElementNode) string

type HashedDomElement

type HashedDomElement struct {
	BranchPathHash string `json:"branchPathHash"`
	AttributesHash string `json:"attributesHash"`
	XpathHash      string `json:"xpathHash"`
}

type HistoryTreeProcessor

type HistoryTreeProcessor struct {
}

func (HistoryTreeProcessor) CompareHistoryElementAndDomeElement

func (h HistoryTreeProcessor) CompareHistoryElementAndDomeElement(domHistoryElement *DOMHistoryElement, domElement *DOMElementNode) bool

func (HistoryTreeProcessor) ConvertDomElementToHistoryElement

func (h HistoryTreeProcessor) ConvertDomElementToHistoryElement(domElement *DOMElementNode) *DOMHistoryElement

func (HistoryTreeProcessor) FindHistoryElementInTree

func (h HistoryTreeProcessor) FindHistoryElementInTree(domHistoryElement *DOMHistoryElement, tree *DOMElementNode) *DOMElementNode

type SelectorMap

type SelectorMap map[int]*DOMElementNode

SelectorMap and DOMState

type ViewportInfo

type ViewportInfo struct {
	ScrollX int `json:"scrollX"`
	ScrollY int `json:"scrollY"`
	Width   int `json:"width"`
	Height  int `json:"height"`
}

func (*ViewportInfo) ToDict

func (v *ViewportInfo) ToDict() map[string]int

type ViewportShortInfo

type ViewportShortInfo struct {
	Width  int `json:"width"`
	Height int `json:"height"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL