Skip to content

Instantly share code, notes, and snippets.

@teal33t
Created February 29, 2020 22:06
Show Gist options
  • Save teal33t/512ff3f29a5c2ba0b8701781daa19642 to your computer and use it in GitHub Desktop.
Save teal33t/512ff3f29a5c2ba0b8701781daa19642 to your computer and use it in GitHub Desktop.
# Using B-spline for simulate humane like mouse movments
def human_like_mouse_move(self, action, start_element):
points = [[6, 2], [3, 2],[0, 0], [0, 2]];
points = np.array(points)
x = points[:,0]
y = points[:,1]
t = range(len(points))
ipl_t = np.linspace(0.0, len(points) - 1, 100)
x_tup = si.splrep(t, x, k=1)
y_tup = si.splrep(t, y, k=1)
x_list = list(x_tup)
xl = x.tolist()
x_list[1] = xl + [0.0, 0.0, 0.0, 0.0]
y_list = list(y_tup)
yl = y.tolist()
y_list[1] = yl + [0.0, 0.0, 0.0, 0.0]
x_i = si.splev(ipl_t, x_list)
y_i = si.splev(ipl_t, y_list)
startElement = start_element
action.move_to_element(startElement);
action.perform();
c = 5
i = 0
for mouse_x, mouse_y in zip(x_i, y_i):
action.move_by_offset(mouse_x,mouse_y);
action.perform();
self.log("Move mouse to, %s ,%s" % (mouse_x, mouse_y))
i += 1
if i == c:
break;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment