Use Browser Chrome: Inject JS script is not supported for this element - Help!

I am attempting to use JavaScript to make clip on a process. I wanted to test this first with to see if I could click on a specific button by element name. It’s not working. I am using Chrome. I came across this error repeatedly.

  • I have chrome installed and active on the Tools settings inside of UiPath.
  • Attached I have the error and the code screenshot correlating with the error.

I’ve searched high and low for a fix for this.

Also will note when it opens UiPath on Google-- I get this pop-up (so I know it’s connected)

Any help would be appreciated :slight_smile:

Hi Alicia! I am not expert in JS Script but why are you using it ? what do you want achieve?

Hi Carmen!

I am attempting to have the Javascript click on a certain selector on the webpage…

The regular click activity both modern and classic have not been able to correctly click it or detect it.

Hi @ajeffers,

Short answer you need to specify an element within the document.getElementsByClassName('gNO89b') because this can fetch you all IDs as well within the Class. So document.getElementsByClassName('gNO89b')[0].click() will click on the Search button in case of Google Search.
Mozilla Documentation : Document.getElementsByClassName() - Web APIs | MDN

But you also have to remember that you cannot search without a value in the input field in google search. If you run the suggested edited code, it will do nothing. In the console you will see undefined as the output. This is because, google will not run its function if the input/search field is empty.

I suggest you change your script a bit and rather than using ClassName and IDs, selectors are better options as they give you the exact target element.

The way you copy selectors is by inspecting the element you are interested in and then right click to get the developer console

function searchGoogle()
  if (document.readyState === "complete");
     // close modal popup
     document.querySelector("#L2AGLb > div").click()

      // set search value
      document.querySelector("body > div.L3eUgb > div.o3j99.ikrT4e.om7nvf > form > div:nth-child(1) > div.A8SBwf > div.RNNXgb > div > div.a4bIc > input").value = 'UiPath Community Forum'

      // run google search 
      document.querySelector("body > div.L3eUgb > div.o3j99.ikrT4e.om7nvf > form > div:nth-child(1) > div.A8SBwf > div.FPdoLc.lJ9FBc > center > input.gNO89b").click()

I named the js file as SearchGoogle.js
ClickElementInvokeJS.xaml (8.8 KB)

There’s no reason for this so you should be figuring out why.

No matter what I attempt to do, even with modern activities, it refuses to attach to the selector.

Attempted your code and it came back this as output:

Hi @ajeffers,

Google chrome is notorious for using your location settings and changing the language both in normal and incognito modes. Even worse is that they change the selectors per country so I am not surprised that the code (selectors) fail in chrome.

You could updated the selectors in the .js file to correspond to your local version of google.


Try running the attached workflow file from my previous post ClickElementInvokeJS.xaml (8.8 KB) (Uses Edge Chromium) and kindly check the incognito window property in the properties panel of Open Browser

The code works on my end on UiPath Studio version 2022.01 with classic browser activity as shown in the screenshot above.

I agree with @postwick UiPath can definitely do the automation you are trying to build both using modern and classic browser activities and it is worthwhile trying to find why it fails on your end.
My aim with providing you the javascript code was to give you and others reading this thread an alternative method. If you can do it with default activities, always prefer that approach.

1 Like

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