The get_cursor_coordinates method encounters a MoveTargetOutOfBoundsException when trying to retrieve cursor coordinates. The current implementation uses string slicing to extract x and y coordinates, leading to potential issues when the error message structure changes.
selenium.common.exceptions.MoveTargetOutOfBoundsException: Message: Move target (30000, 30000) is out of bounds of viewport dimensions (1280, 595) Stacktrace:...
Description
The get_cursor_coordinates method attempts to extract cursor coordinates from a MoveTargetOutOfBoundsException error. However, the current implementation relies on string slicing, which may lead to errors if the error message format changes.
The get_cursor_coordinates method should reliably extract x and y coordinates from the MoveTargetOutOfBoundsException error message, ensuring robustness against potential changes in the error message format.
Actual Results
The current implementation uses string slicing, which might break if the error message format changes.
Environment
Python version: 3.10
Selenium version: 3.14.0
HLISA version: 1.6.1
Operating System: Windows
Possible Solution
Proposed solution using regular expressions:
def get_cursor_coordinates(driver):
MOVE_PIXELS = 30000
try:
ac = ActionChains(driver)
ac.move_by_offset(MOVE_PIXELS, MOVE_PIXELS)
ac.perform()
except MoveTargetOutOfBoundsException as ex:
match = re.search(r'.*\((\d+),\s*(\d+)\)', str(ex))
x = match.group(1)
y = match.group(2)
try:
x = int(x)
y = int(y)
except Exception as e:
raise NoCursorCoordinatesException() # If the coordinates are not integers, something went wrong
if x < 0 or y < 0:
raise NoCursorCoordinatesException()
return (x - MOVE_PIXELS, y - MOVE_PIXELS)
raise NoCursorCoordinatesException() # If no exception occured, something went wrong
Issue Summary
The
get_cursor_coordinates
method encounters aMoveTargetOutOfBoundsException
when trying to retrieve cursor coordinates. The current implementation uses string slicing to extract x and y coordinates, leading to potential issues when the error message structure changes.selenium.common.exceptions.MoveTargetOutOfBoundsException: Message: Move target (30000, 30000) is out of bounds of viewport dimensions (1280, 595) Stacktrace:...
Description
The
get_cursor_coordinates
method attempts to extract cursor coordinates from aMoveTargetOutOfBoundsException
error. However, the current implementation relies on string slicing, which may lead to errors if the error message format changes.Steps to Reproduce
Expected Results
The
get_cursor_coordinates
method should reliably extract x and y coordinates from theMoveTargetOutOfBoundsException
error message, ensuring robustness against potential changes in the error message format.Actual Results
The current implementation uses string slicing, which might break if the error message format changes.
Environment
Possible Solution
Proposed solution using regular expressions: