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

753
Visualizações
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 à 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