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

207
Views
Javascript: ¿Cómo enfoco la barra de búsqueda de YT?

Uso un javascript para establecer el foco/cursor en el primer elemento de entrada. Funciona bien en casi todas las circunstancias, pero no en la página siguiente:

 https://www.youtube.com/

El cuadro de texto que esperaba recibir el foco es este: ingrese la descripción de la imagen aquí

Tiene el siguiente selector (copiado de Chrome):

 #search

Este es su Xpath:

 //*[@id="search"]

XPath completo:

 /html/body/ytd-app/div[1]/div/ytd-masthead/div[3]/div[2]/ytd-searchbox/form/div[1]/div[1]/input

Y este es su código:

 <input id="search" autocapitalize="none" autocomplete="off" autocorrect="off" name="search_query" tabindex="0" type="text" spellcheck="false" placeholder="Suchen" aria-label="Suchen" role="combobox" aria-haspopup="false" aria-autocomplete="list" dir="ltr" class="ytd-searchbox" style="outline: none;">

Sin embargo, no logré seleccionar este cuadro de búsqueda.

¿Qué me estoy perdiendo?

Este es el código javascript:

 function pSetFocus() { var element = document.querySelector("*[autofocus]"); if (element) { } else { element = document.querySelector("form input:not([type=hidden])"); } if (element) { } else { element = document.querySelectorAll("#search.ytd-searchbox"); //Here is try to select the YT search bar... } if (element) { } else { return; } element.selectionStart = element.selectionEnd = element.value.length; element.focus(); var y = element.getBoundingClientRect().top + window.scrollY; window.scroll( { top: y, behavior: "smooth" }); };

¡Gracias!

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

0

Descubrí otro (el más importante) problema:

Le doy a mi navegador basado en CEF3 el código de función en sí, pero no lo llamé.

ahora estoy usando

 Me.webkitx1.Eval(somecodeWithoutFunctionDeclaration)

Funciona.

Antes usaba:

 Me.webkitx1.Eval(somecodeWithFunctionDeclaration)

Aquí puedes ver cómo eliminé el encabezado de la función (lo que hizo que funcionara para mí):

 var element = document.querySelector("*[autofocus]"); if (element) { } else { element = document.querySelector("form input:not([type=hidden])"); } if (element) { } else { element = document.querySelector("#search"); } if (element) { } else { return; } element.selectionStart = element.selectionEnd = element.value.length; element.focus(); var y = element.getBoundingClientRect().top + window.scrollY; window.scroll( { top: y, behavior: "smooth" });
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!