Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

122
Views
¿Cómo obtener una matriz de elementos (botones) basados en aria-label en Playwright con locator.evaluateAll()?

Estoy tratando de obtener una matriz de elementos dom de uno de los dos valores de etiqueta aria. Estoy tratando de hacer esto con el método locator.evaluateAll .

Actualmente, esto es todo lo que he conseguido; Estoy tratando de tomar todos los botones en mi DOM y crear una matriz de aquellos que poseen un atributo de etiqueta aria específico:

 const elements = this.page.locator('button'); const allSigButtons = await elements.evaluateAll( (button) => `${button}[aria-label='Sign']` || `${button}[aria-label='Initial']` );

Cuando imprimo mi matriz allSigButtons en la consola, obtengo:

 [object HTMLButtonElement],[object HTMLButtonElement],[object HTMLButtonElement],[object HTMLButtonElement],[object HTMLButtonElement],[object HTMLButtonElement],[object HTMLButtonElement],[object HTMLButtonElement],[object HTMLButtonElement],[object HTMLButtonElement],[object HTMLButtonElement],[object HTMLButtonElement],[object HTMLButtonElement],[object HTMLButtonElement][aria-label='Sign']

Claramente estoy haciendo algo mal!

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Creo que está buscandoselectores de CSS delimitados por comas (OR lógico) :

 const playwright = require("playwright"); const html = ` <body> <button aria-label="Sign">foo</button> <button aria-label="Signy">NO</button> <button aria-label="Initial">bar</button> <button aria-label="Initial">baz</button> <button aria-label="Initia">NOT ME</button> </body> `; let browser; (async () => { browser = await playwright.chromium.launch({headless: true}); const page = await browser.newPage(); await page.setContent(html); const sel = "button[aria-label='Sign'], button[aria-label='Initial']"; const btns = await page.locator(sel); console.log(await btns.allTextContents()); // => [ 'foo', 'bar', 'baz' ] })() .catch(err => console.error(err)) .finally(() => browser?.close()) ;
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!