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

250
Visualizações
Selenium--driver.execute_script() wont work

I execute a javascript with driver.execute_script but NOTHING occurs when I do--the system simply goes to the next python code line

Thoughts? webscraping in webpage--using JavaScript in Console to datamine. The jScript works wonderfully when I put it to the webconsole

JavasCRIPT:

let email = '';
let contacts = document.querySelectorAll('div.contact-section');
for (let i = 0; i < contacts.length; i++) {
  if (contacts[i].getAttribute('automation-id') === 'contact-true-owner') {
    ele = contacts[i]
  }
}
let links = ele.querySelectorAll('address > a')
let last = links.length - 1;
email = links[last].innerText;
console.log(email);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Add return to script

This script actually do nothing you could detect from python code. The last line doesn't return anything..

Try to add the return statement:

...
email = links[last].innerText;
console.log(email);
return email

And also, it looks like the job you trying to do with driver.execute_script is just to locate the element and call .innerText. I gess it could be solved by providing the right xpath query (maybe css selector also OK, but xpath should work exactly).

I mean there is more strait-forward way to solve this issue, not just delegate it to for loop in driver.execute_script. But it's on your choice.

I'll be able to help you with xpath if you share the page-source. But it's optional.

With xpath

The idea is to perform 2 steps:

1 Find the element by xpath (other selector).

2 Pass it to executeScript as argument.

element = driver.find_element_by_xpath("//div[contains(@class, 'contact-section')][@automation-id='contact-true-owner']//address/a[last()]")

text = driver.execute_script('return arguments[0].innerText;', element)
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