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

170
Views
Error al asignar valor a InputElement usando Titiritero

Estoy tratando de establecer un valor para un elemento Input/TextArea en html usando titiritero sin éxito. El código se transpila con mecanografiado.

Aquí uso YouTube como ejemplo.

Primero debe navegar a youtube, luego seleccionar el cuadro de entrada con el selector css de pseudoclase y establecer el valor de acuerdo con las variables: prefijo y título.

El script se cierra tan pronto como comienza a ejecutar page.eval. No estoy seguro si estoy usando el selector css incorrecto. Puede haber un problema cuando intento asignar una cadena a la propiedad "valor" también.

 (async ()=>{ const searchbox='html>body>ytd-app>div>div>ytd-masthead>div:nth-of-type(3)/div:nth-of-type(2)/ytd-searchbox/form/div:first-of-type/div:first-of-type/input' const puppeteer = require("puppeteer") const browser = await puppeteer.launch({headless:false, defaultViewport: null, slowMo: 100}); const page = await browser.newPage(); await page.goto('https://www.youtube.com/'); await uploadPhoto("Some", " Video"); async function uploadPhoto(prefix:string, caption:string) { await page.evaluate( (searchbox:string, prefix:string, caption:string) => { (document.querySelector(searchbox) as HTMLInputElement).value = `${prefix} ${caption}`}, searchbox, prefix, caption) } console.log("finish") })();
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Creo que debería eliminar todos los tipos de su función de evaluate , ya que esta función se ejecutará directamente en el navegador y creo que los tipos harían que fallara:

 async function uploadPhoto(prefix:string, caption:string) { await page.evaluate( (searchbox, prefix, caption) => { document.querySelector(searchbox).value = `${prefix} ${caption}` }, searchbox, prefix, caption) }

Una solución más fácil es usar el type de método de la clase ElementHandle :

 const searchInput: ElementHandle<Element> = await page.waitForSelector(searchbox, { timeout: 5000 }); await searchInput.type("Some text to search");

o type desde la clase de Page :

 await page.type(searchbox, "Some text to search");
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!