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.
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);