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

442
Views
El elemento existe en la página en Playwright.js pero $ devuelve nulo

en mi código js de muestra

 let targetXpath = 'xpath=//html/body/div[1]/div[2]/div[1]/div[1]/div/span[3]/div[2]/div[3]/div/div/div/div/div/div[2]/div/div/div[1]/h2/a/span' let name1 = await page.locator(targetXpath).evaluate(node => node.innerText) console.log(name1) // prints the name of the item being looked at on the xpath edit: I should have noted I tried both statements separately. So if you comment out name1 and console.log(name1), And I was trying to do this on amazon searching for nvidia 3060 let nameDollar1 = await page.$(targetXpath) console.log(nameDollar1) // prints null

¿Cómo puede el dramaturgo ver esto cuando llama a evaluar pero no puede verlo cuando usa $()?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Los localizadores esperan que aparezcan los elementos y tienen habilitado el modo estricto (se asegura de que solo haya 1 elemento en la página con el selector dado). Page.$ y Page.$$ por otro lado (algunos enlaces de lenguaje de Playwright también lo llaman querySelector y querySelectorAll) no esperan los elementos y tampoco tienen habilitado el modo estricto. Es por eso que es nulo en tu caso.

Tenga también en cuenta que los localizadores resuelven el elemento cuando se ejecuta la acción (hacer clic, rellenar, etc.) y $/$$ resuelven el elemento cuando se les llama. Consulte aquí para obtener más información: https://playwright.dev/docs/locators

Regla general: utilice siempre localizadores.

about 4 years ago · Juan Pablo Isaza 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!