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

140
Views
Cómo hacer clic en un elemento DOM específico (no en un botón) con js puro que actúa como selenuim.click()

Necesito escribir un script en el sitio existente (no puedo cambiar su código)

 orders = document.getElementsByClassName('table-row'); for (order of orders){ let text = order.innerText; let btn = order.getElementsByClassName('icon-btn')[0]; btn.click() }

El problema es que btn no es un botón. Es un SVG en el que se debe hacer clic (procesado en js interno del sitio web)

 <svg width="1.2em" height="1.2em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32" class="icon-btn align-middle"><path d="M30 10.68l-2-6A1 1 0 0 0 27 4H5a1 1 0 0 0-1 .68l-2 6A1.19 1.19 0 0 0 2 11v6a1 1 0 0 0 1 1h1v10h2V18h6v10h16V18h1a1 1 0 0 0 1-1v-6a1.19 1.19 0 0 0 0-.32zM26 26H14v-8h12zm2-10h-4v-4h-2v4h-5v-4h-2v4h-5v-4H8v4H4v-4.84L5.72 6h20.56L28 11.16z" fill="currentColor"></path></svg>

entonces, por defecto, no tiene la propiedad click()

 VM844:9 Uncaught TypeError: Cannot read properties of undefined (reading 'click') at <anonymous>:9:13

Entonces, la tarea es simplemente hacer clic en ese elemento, y luego ese sitio interno js procesaría este clic y me mostraría una ventana emergente.

El evento esperado es como selenium.click() que simplemente imita hacer clic en el objeto

Traté de agregar btn.addEventListener('click', ...)

 for (order of orders){ console.log(order) let text = order.innerText; let btn = order.getElementsByClassName('icon-btn')[0]; btn.addEventListener("click", function(){ alert("Hello World!"); }) }

y tengo un error

 VM1553:9 Uncaught TypeError: Cannot read properties of undefined (reading 'addEventListener') at <anonymous>:9:13 (anonymous) @ VM1553:9
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

document.getElementsByClassName('icon-btn')[0]._vei.onClick.value()
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!