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

218
Visualizações
How to click a lot of elements in Javascript without errors?

I have been trying to download all USA and CANADA servers here on Nord VPN website: https://nordvpn.com/ovpn/

I tried to manually download it but it is time consuming to scroll down every time and identify each US related servers, so i just wrote simple Javascript that can be run on Chrome Inspect Element Console:

var servers = document.getElementsByClassName("mr-2");
var inc_servers = [];
for (var i = 0; i < servers.length; i++) {
  var main_server = servers[i];
  var server = servers[i].innerText;
  if(server.includes("ca")){
        var parent_server = main_server.parentElement.parentElement;
        parent_server.querySelector(".Button.Button--primary.Button--small").click();
        inc_servers.push(server);
  }
}
console.log(JSON.stringify(inc_servers));

I also wrote simple python script that automatically click "save" file:

while True:
    try:
        app2 = pywinauto.Application().connect(title=u'Save As', found_index=0)
        app2.SaveAs.Save.click()
    except:
        pass

It gets all the elements, it works there, however, when I let javascript click each element, maybe because of too many elements, it returns an error:

VM15575:8 Throttling navigation to prevent the browser from hanging. See https://crbug.com/1038223. Command line switch --disable-ipc-flooding-protection can be used to bypass the protection

Are there any other best alternative for my problem? Or maybe how to fix the error message above? I tried running this command in my command prompt: switch --disable-ipc-flooding-protection

but it returns also an error: 'switch' is not recognized as an internal or external command, operable program or batch file.

I only know basic Javascript and Python. Thanks

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

So right off the bat, your program is simply downloading files too fast.

Adding a small delay between each file download allows your JavaScript to run.

var servers = document.getElementsByClassName("mr-2");
var inc_servers = [];
for (var i = 0; i < servers.length; i++) {
  var main_server = servers[i];
  var server = servers[i].innerText;
  if(server.includes("ca")){
        var parent_server = main_server.parentElement.parentElement;
        // Add 1 second delay between each download (fast enough on my computer.. Might be too fast for yours.)
        await new Promise(resolve => setTimeout(resolve, 1000));
        parent_server.querySelector(".Button.Button--primary.Button--small").click();


  }
}
// Remove the logging. Just tell the user that it's worked
console.log("Done downloading all files.");

This is more of a temporary solution, but this script seems like it only needs to be run once, so it'll work for now.

(your python code runs fine. Nothing to do there)

Hope this helped.

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