TestProject Forum

To run a javascript code to input a value in an element

I am new to test project and we have a field in the application where we need to input a number in certain format. I have a Java script code for the same. If we use selenium all we have to do is find this textbox and input a value by calling this function which generates a random number.

Can i do the same from test project while recording the test. Tried using java script addon Web extension’s Execute Javascript, but i cant use it on a particular element.

Please help me to use this code to generate a number and input it in this field.


Hi @sravani,
You can add your function to the execute JavaScript action in TestProject,
then take the element JS path using the devtools

Then use that use the JS path to put value in from function for example:

I have a function that multiplies two numbers

function myFunction(p1, p2) {
  return p1 * p2;   

then i will copy the element JS path and will add .value=myFunction(4,3)

the end result of this will be in this example google search textbox

function myFunction(p1, p2) {
  return p1 * p2;   
document.querySelector("body > div.L3eUgb > div.o3j99.ikrT4e.om7nvf > form > div:nth-child(1) > div.A8SBwf > div.RNNXgb > div.SDkEP > div.a4bIc > input").value=myFunction(3,4);

this in this case will type 12.

Please let me know if that solved your issue

Kind regards

I followed the same and it worked. Thanks