I am attempting to use JavaScript to make clip on a process. I wanted to test this first with google.com 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)
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
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.
OR
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.