MCPcopy Create free account
hub / github.com/InverseUI/InverseUI-Recorder / getElementLabels

Function getElementLabels

util/playwright_selector.js:221–245  ·  view source on GitHub ↗

* Get element labels (from selectorUtils.ts lines 115-131)

(element)

Source from the content-addressed store, hash-verified

219 * Get element labels (from selectorUtils.ts lines 115-131)
220 */
221function getElementLabels(element) {
222 // Check aria-labelledby first
223 const labelledBy = element.getAttribute('aria-labelledby');
224 if (labelledBy) {
225 const ids = labelledBy.split(' ').filter(id => id);
226 const labels = ids.map(id => document.getElementById(id)).filter(el => el);
227 if (labels.length)
228 return labels.map(label => elementText(label));
229 }
230
231 // Check aria-label
232 const ariaLabel = element.getAttribute('aria-label');
233 if (ariaLabel && ariaLabel.trim())
234 return [{ full: ariaLabel, normalized: normalizeWhiteSpace(ariaLabel), immediate: [ariaLabel] }];
235
236 // Check HTML labels for form elements
237 const isNonHiddenInput = element.nodeName === 'INPUT' && element.type !== 'hidden';
238 if (['BUTTON', 'METER', 'OUTPUT', 'PROGRESS', 'SELECT', 'TEXTAREA'].includes(element.nodeName) || isNonHiddenInput) {
239 const labels = element.labels;
240 if (labels && labels.length)
241 return [...labels].map(label => elementText(label));
242 }
243
244 return [];
245}
246
247/**
248 * Get accessible name for element (simplified from roleUtils.ts lines 504-528)

Callers 3

getElementAccessibleNameFunction · 0.85
countMatchingElementsFunction · 0.85
buildCandidatesFunction · 0.85

Calls 2

elementTextFunction · 0.85
normalizeWhiteSpaceFunction · 0.85

Tested by

no test coverage detected