riflosnake / HumanCursor

Simulate Human Cursor Movement for Automated Scripts
MIT License
87 stars 16 forks source link

TypeError: 'float' object cannot be interpreted as an integer #11

Closed webphax closed 7 months ago

webphax commented 7 months ago

I'm using the click_on(element) method within a selenium environment. Most of the time it's working fine, but from time to time I get the following error when using a WebElement (element is valid and element.location = {'x': 1453, 'y': 987} within the viewport)

Traceback (most recent call last):
  File "/x/x/x/lt-bot/.venv/lib/python3.12/site-packages/humancursor/utilities/human_curve_generator.py", line 72, in generate_internal_knots
    knotsX = np.random.choice(range(l_boundary, r_boundary) or l_boundary, size=knots_count)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'float' object cannot be interpreted as an integer

During handling of the above exception, another exception occurred:

  File "/x/x/x/lt-bot/.venv/lib/python3.12/site-packages/humancursor/web_cursor.py", line 50, in click_on
    self.move_to(
  File "/x/x/x/lt-bot/.venv/lib/python3.12/site-packages/humancursor/web_cursor.py", line 30, in move_to
    self.origin_coordinates = self.human.move_to(
                              ^^^^^^^^^^^^^^^^^^^
  File "/x/x/x/lt-bot/.venv/lib/python3.12/site-packages/humancursor/utilities/web_adjuster.py", line 73, in move_to
    human_curve = HumanizeMouseTrajectory(
                  ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/x/x/x/lt-bot/.venv/lib/python3.12/site-packages/humancursor/utilities/human_curve_generator.py", line 11, in __init__
    self.points = self.generate_curve(**kwargs)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/x/x/x/lt-bot/.venv/lib/python3.12/site-packages/humancursor/utilities/human_curve_generator.py", line 40, in generate_curve
    internalKnots = self.generate_internal_knots(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/x/x/x/lt-bot/.venv/lib/python3.12/site-packages/humancursor/utilities/human_curve_generator.py", line 78, in generate_internal_knots
    knotsY = np.random.choice(
             ^^^^^^^^^^^^^^^^^
  File "numpy/random/mtrand.pyx", line 951, in numpy.random.mtrand.RandomState.choice
ValueError: 'a' cannot be empty unless no samples are taken
riflosnake commented 7 months ago

Should be something wrong on your pc, because that error is caught by an except TypeError 2 lines below.

I know it sounds dumb but maybe try restarting computer 😀.

webphax commented 7 months ago

I tried it several times and it keeps crashing randomly with the same element (same x, y coordinates). I couldn't figure out why and had to remove HumanCursor again :(