Execute Javascript directly without Generating a .js file

I want to execute the below because it’s hard to get appropriate selector for the button.

document.querySelector(“body > div.modal.fade.seller-layer-modal.in > div > div > div.modal-footer > div > button.btn.btn-primary”).click()

It seems many people use the way of generating a .js file and executing it with “Inject JS Script” activity as follows.

image

But because it is too much for me I am wondering whether I can just pass the below

document.querySelector(“body > div.modal.fade.seller-layer-modal.in > div > div > div.modal-footer > div > button.btn.btn-primary”).click()

into this field. image

Please let me know how the format should be if this is at all possible.

Thank you!

Hi
We can also pass the js script as a string here buddy like You can write it here as a string, or add the full path of a .js file which contains the code to be executed. * It should contain a single anonymous function as in the example below.

  • JavaScript
function (element, input) {
    return "result";
}

Where:

  • element - represents the HTML element corresponding to the calling UI node.
  • input - the input string provided by the caller.

Cheers @Daun

@Palaniyappan, Thank you!

Could you give me the exact string to be put in the “ScriptCode” section

image

when I want to use this as a string?

document.querySelector(“body > div.modal.fade.seller-layer-modal.in > div > div > div.modal-footer > div > button.btn.btn-primary”).click()

Hello, Check this out.

https://docs.uipath.com/activities/docs/inject-js-scriptInject JS.zip (11.7 KB)

Thank you @rmunro for your answer.

So, is there no way of executing

document.querySelector(“body > div.modal.fade.seller-layer-modal.in > div > div > div.modal-footer > div > button.btn.btn-primary”).click()

like executing in the Google Chrome Console pane, ie., without creating a .js file?

Yes,

Just enter it between quotes like this: “document.querySelector(“body > div.modal.fade.seller-layer-modal.in > div > div > div.modal-footer > div > button.btn.btn-primary”).click()”

@rmunro
It says I need to end the formula. Maybe because of the double quotations within it.

“document.querySelector(“body > div.modal.fade.seller-layer-modal.in > div > div > div.modal-footer > div > button.btn.btn-primary”).click()”

I tried putting 4 double quotations within it but it doesn’t work, either.

“document.querySelector(”""“body > div.modal.fade.seller-layer-modal.in > div > div > div.modal-footer > div > button.btn.btn-primary”""").click()"

“document.querySelector(‘body > div.modal.fade.seller-layer-modal.in > div > div > div.modal-footer > div > button.btn.btn-primary’).click()”

Single quotations in front of “body” and after “btn-primary” solved it!

1 Like

Good job

1 Like

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