Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

754
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!