instantcode
Version:
AI-powered web inspection tool - Pick elements and get instant AI assistance
55 lines (54 loc) • 1.7 kB
TypeScript
/**
* Enhanced XPath and CSS selector utilities for browser environment
*/
export interface ElementSelector {
xpath: string;
cssSelector: string;
uniqueId?: string;
position?: {
index: number;
total: number;
};
}
export declare class XPathUtils {
static generateXPath(element: Element): string;
private static getXPathStep;
private static getXPathIndex;
private static isValidId;
/**
* Generate optimized CSS selector using optimal-select library
*/
static generateOptimalSelector(element: Element): string;
/**
* Generate enhanced CSS selector optimized for browser environment
*/
static generateEnhancedCSSSelector(element: Element): string;
/**
* Validate XPath by testing if it uniquely identifies the element
*/
static validateXPath(xpath: string, targetElement: Element): boolean;
/**
* Validate CSS selector by testing if it uniquely identifies the element
*/
static validateCSSSelector(selector: string, targetElement: Element): boolean;
/**
* Find element using XPath
*/
static findElementByXPath(xpath: string): Element | null;
/**
* Generate comprehensive selector information for an element
*/
static generateElementSelector(element: Element): ElementSelector;
/**
* Check if an ID is unique in the document
*/
private static isUniqueId;
/**
* Generate multiple selector strategies for robust element identification
*/
static generateRobustSelectors(element: Element): {
primary: ElementSelector;
fallbacks: string[];
confidence: 'high' | 'medium' | 'low';
};
}