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

752
Vistas
Selenium python find and replace text

I'm trying to replace text within a string on Wagtail backend using Selenium and Python. My strategy is:

  • Find the element that contains the text with contains(text()
  • Replace the string I need to replace (in this case some price)
  • substitute the old text with the new one

element = driver.find_element(By.XPATH,"//*[contains(text(), '17,30')]")
newprice= str(element.text).replace('17,30',"1000")
driver.execute_script("arguments[0].innerText =  ",newprice, element)
This is the error message I get

selenium.common.exceptions.JavascriptException: Message: javascript error: Unexpected identifier

The following code works but doesn't do what I need. The element that contains "17,30" also contains other text. With the following code, the whole text will be substituted by "1000".

element = driver.find_element(By.XPATH,"//*[contains(text(), '17,30')]")
driver.execute_script("arguments[0].innerText =  '1000'", element)

about 4 years ago · Juan Pablo Isaza
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