Check the checkbox based on the text with UiPath

I need to check the checkbox based on the text in HTML
and I have the solution with Javascript but in UiPath is not working when I add “Inject Js Script” Edit fiddle - JSFiddle - Code Playground

function ExecuteScript() function checkBoxFromLabelText(str) {
  const labels = [...document.querySelectorAll('label')];
  const label = labels.find(label => label.textContent.trim() === str);
  if (label) label.querySelector('[type="checkbox"]').checked = true;

}
checkBoxFromLabelText('Text 1');

I was trying this method and his not working:

"function ExecuteScript() { function checkBoxFromLabelText(str) { " +
  " const labels = [...document.querySelectorAll('label')]; " +
  " const label = labels.find(label => label.textContent.trim() === str); " +
  " if (label) label.querySelector('[type=""checkbox""]').checked = true; " +
 "} " +
 "checkBoxFromLabelText('Text 1');} "

Hi @radouane

Have you tried Check/Uncheck activity in the UiPath.

From your code I can see that you identify the checkbox using label text value and also you have parameterized the label value for dynamic selection.

We can follow similar approach in Check/Uncheck activity and pass the label text as variable in selector which allows UiPath to select the checkbox dynamically.

Check/Uncheck (uipath.com)

Thanks
John

1 Like

thank you so much @johnfelix it’s working 100%, I don’t need Inject Js Any more.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.