Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

245
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda