# Running onclick JavaScript command using 'Inject JS Script'

**URL:** <https://forum.uipath.com/t/running-onclick-javascript-command-using-inject-js-script/461114>\
**Category:** Studio\
**Tags:** javascript, web, studio, uiautomation, activities\
**Created:** [July 31, 2022, 11:49pm UTC](https://forum.uipath.com/t/running-onclick-javascript-command-using-inject-js-script/461114 "2022-07-31T23:49:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mitesh\_Sachania](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/mitesh_sachania/32/181618_2.png) [@Mitesh\_Sachania](https://forum.uipath.com/u/Mitesh_Sachania)\
**Post date:** [July 31, 2022, 11:49pm UTC](https://forum.uipath.com/t/running-onclick-javascript-command-using-inject-js-script/461114/1 "2022-07-31T23:49:51Z")

</div>

Hi there,

There’s an automation that I’m building which requires clicking a link nested under 6 different levels of hidden HTML tags, in order to reach the target link I’m having to click on each HTML tag until I open all 6 levels, only just to click on the link.

The link I’m trying to click on has a piece of code written in javascript; the onlick looks like onlick=“javascript:code” whilst the href looks like this href=“javascript:enq(‘enq next.page’)”.

When I click on the link myself it opens up a new pop up with data I’m trying to reach, and I am also able to replicate this by running the function using Google Chrome’s Inpect Console. However, whenever I try to run this using “Inject Js Script”, it says “ReferenceError: enq is not defined.”

Could someone please kindly help me with this?

Many thanks in advance

---

<div class="post-metadata">

**Author:** ![jack.chan](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/jack.chan/32/176616_2.png) [@jack.chan](https://forum.uipath.com/u/jack.chan)\
**Post date:** [August 1, 2022, 1:03am UTC](https://forum.uipath.com/t/running-onclick-javascript-command-using-inject-js-script/461114/2 "2022-08-01T01:03:21Z")

</div>

> [@Mitesh\_Sachania](#):
>
> The link I’m trying to click on has a piece of code written in javascript; the onlick looks like onlick=“javascript:code” whilst the href looks like this href=“javascript:enq(‘enq next.page’)”.

@Mitesh_Sachania  
does the link have an id?

e.g. .if the element is something like this  
`<a id = "abc" onclick = "....."></a>`

then you can change your inject js function to:  
`document.getElementById("id").Click();`

you can also use

```auto
document.getElementsByClassName
document.getElementsByTagName

```

etc

---

<div class="post-metadata">

**Author:** ![Nithinkrishna](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/nithinkrishna/32/561519_2.png) [@Nithinkrishna](https://forum.uipath.com/u/Nithinkrishna)\
**Post date:** [August 1, 2022, 1:48am UTC](https://forum.uipath.com/t/running-onclick-javascript-command-using-inject-js-script/461114/3 "2022-08-01T01:48:39Z")

</div>

Hey @Mitesh_Sachania

Please show us the code of `InjectJS` ?

Thanks  
#nK
