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

362
Views
¿Cómo usar XPath en una ventana recién abierta?

Con el siguiente código (destinado a un bookmarklet), estoy tratando de abrir una nueva ventana, buscar ciertos elementos de intervalo y hacer clic en cada uno de ellos. Sin embargo, no puedo acceder al código de la nueva ventana a través de XPath.

  • Insertar el código (copiar y pegar) de la clickElem function directamente en la nueva pestaña funciona bien
  • CORS no es un problema ya que es el mismo dominio/subdominio/protocolo
  • También he estado siguiendo esta respuesta .

JavaScript:

 const w = window.open('https://example.com', 'Example', 'width=500, height=500'); w.clickElem = () => { const xpath = '//span[text()="Click here"]'; const selectedNodeElements = w.document.evaluate(xpath, document, null, XPathResult.ANY_TYPE, null); let currentNode = selectedNodeElements.iterateNext(); while (currentNode) { currentNode.click(); currentNode = selectedNodeElements.iterateNext(); } } setTimeout(w.clickElem, 8000);

Cuando intento acceder al texto a través currentNode.textContent , recibo el siguiente error:

"Error in protected function: Cannot read properties of null (reading 'textContent')"

¡Agradecido por cada pista!

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

0

¿Estás seguro de que ya estás dentro de tu ficha? Estoy pensando en algo que necesitas para obtener la pestaña activa como esta .

about 4 years ago · Juan Pablo Isaza Report

0

Finalmente encontré mi propio error después de revisar mi código una y otra vez y encontrar esta respuesta . .iterateNext() no funcionó porque el nodo de contexto se configuró incorrectamente en document . En su lugar, debería ser w.document para hacer referencia a la ventana recién abierta.

 const selectedNodeElements = w.document.evaluate(xpath, w.document, null, XPathResult.ANY_TYPE, null);
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!