Random position Click action

Hi,
Im looking for random click(XClick) within selected area.

For example as a Command I choose: XClick and as a Target I select some button on website.

Everytime i run this script program click the button in his center.
How to do some random offset to make every new click in different position within this button area? Is it possible?

center

This is above script:

  "Commands": [
    {
      "Command": "open",
      "Target": "http://google.com",
      "Value": ""
    },
    {
      "Command": "XClick",
      "Target": "vncpcj_dpi_96.png",
      "Value": ""
    }
  ]
}

Here is a solution:

  • VisualAssert | vncpcj_dpi_96.png (your button, now the center xy are stored in !imagex and !imagey )
  • executeScript_Sandbox | return ${!imagex} + Math.floor((0.5-Math.random())*40) | x1 Add randomly up +/- 20px to the x-value
  • executeScript_Sandbox | return ${!imagey} + Math.floor((0.5-Math.random())*20) | y1 Add randomly up to +/- 10px to the y-value
  • XClick | x1,y1
3 Likes

It works, thank you :slight_smile:

Hey!Please can you write down the code? I tried to write in these but unfortunetly didint worked

@cr1s Can you post your sample code? What is not working?

1 Like

Didnt worked for me too

“Cannot convert undefined or null to object”

The full code

{
“Name”: “googlerandom”,
“CreationDate”: “2023-1-9”,
“Commands”: [
{
“Command”: “selectWindow”,
“Target”: “title=Google”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “visualAssert”,
“Target”: “vncpcj_dpi_96.png”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “executeScript_Sandbox”,
“Target”: “return ${!imagex} + Math.floor((0.5-Math.random())*40)”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “executeScript_Sandbox”,
“Target”: “return ${!imagey} + Math.floor((0.5-Math.random())*20)”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “XClick”,
“Target”: “x1,y1”,
“Value”: “”,
“Description”: “”
}
]
}