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

207
Vistas
Remove a sub-string in a string to rewrite a robust xpath

I need to remove the value attribute from this xpath. (In this example there are two value attributes).

I create the xpath in a string:

"xpath": "//iframe[@title=\"s='replaceable-modal-title'>Compléter mes entretiens</span><input type='hidden' id='assessDurationIdverif' value='2091' /><input type='hidden' id='employeeIdverif' value='1368' />\"]/html/body/div[2]/section/div/div[4]/div/form/div[2]/div/div[2]/div/div/textarea"

My first idea was to use the String#replace method to replace attribute's value with an empty string:

string.replace(/value=(2091)/g,'test') 

My problem is that the value attribute does not have the same value when I refresh the page.

I just want to know how to generically replace the number by undefined character.

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

You're on the right track with String#replace and a regular expression.

To handle the value attribute changing when the page reloads, use the \d digit character class which represents any character in 0-9. Using \d* matches zero or more digits and \d+ matches one or more digits.

Here's an example that matches all value attributes with digits in their values and replaces the whole attribute with an empty string:

const foo = "//iframe[@title=\"s='replaceable-modal-title'>Compléter mes entretiens</span><input type='hidden' id='assessDurationIdverif' value='2091' /><input type='hidden' id='employeeIdverif' value='1368' />\"]/html/body/div[2]/section/div/div[4]/div/form/div[2]/div/div[2]/div/div/textarea";

const bar = foo.replace(/value='\d+'/g, '');

console.log(foo);
console.log(bar);

about 4 years ago · Santiago Gelvez 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