Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

146
Visualizações
How to click a specific DOM element (not button) with pure js that act like selenuim.click()

I need to write script to existing site(i can't change its code)

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

The problem is that btn is not button. It's an SVG that has to be clicked on (processed in internal js of website)

<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>

so by default it has not click() property

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

So the task is just click on that element, and after that internal site js would process this click and give me popup.

Awaited event is like selenium.click() that just immitate click on object

I tried to add 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!"); })
    }   

and i got 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 Respostas
Responde à pergunta

0

document.getElementsByClassName('icon-btn')[0]._vei.onClick.value()
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda