How to replace text in HTML document?

Hello Community,

I am trying to replace the text within the HTML document, but when i try to replace, i dont want the class name to be changed (because sometimes the class name will have the same value as that of the content), Just the content needs to be changed by reffering to the lookup table.

Input:

<p class="message">Start guessing message...</p>
<p class="label-highscore">
   🥇 My score: <span class="highscore">My highscore is 10</span>
 </p>

The data that has to be replaced:
original - Changed into
message – messageCA
highscore – highscoreCA

Output:

<p class="message">Start guessing messageCA...</p>
<p class="label-highscore">
🥇 My Score: <span class="highscore">My highscoreCA is 10</span>
</p>

Thank you

Hey,

Can you put all this html format in a string or store in a text file and then read.

Use variable for your changing values and replace them once you read them in UiPath throiugh string replace function.

i can do it, but i dont want the class name to be changed. I just want the actual content to be changed, nothing else

Is this content dynamic, or can you parametrize the content ?

This might be silly as a solution, but if you’re going for a “replace string with string” approach, can’t you use an entire phrase as a match? For example, instead of searching for “highscore” - which will result in wrong matches - can’t you search for “My highscore is” and replace it with “My highscoreCA is” ? This will only work if you have fixed occurrences of these sentences, and if you have just 1 or 2 so that you don’t have to hard-code everything.

I agree, string replacement would not be an apt solution, however how do you know which strings you want to replace in html?

Another solution is to use a regex finds a match for your text to replace in between the symbols “>” and “<”