Advertisement
silicogel

Untitled

Aug 24th, 2023
799
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. from selenium.webdriver import ActionChains
  2. from HLISA.errors import NoCursorCoordinatesException
  3.  
  4. def get_cursor_coordinates_patched(driver):
  5.     try:
  6.         pixel = driver.find_element(By.ID, 'pixel')
  7.     except:
  8.         script = '''var elem = document.createElement('div');elem.id = 'pixel';elem.style.cssText = 'width:3px;height:3px;pointer-events:none;background-color:red;position:absolute;';elem.style.left = '0px';elem.style.top = '0px';document.body.appendChild(elem);document.addEventListener("mousemove", function(e) {let pixel = document.getElementById("pixel");pixel.style.left = e.pageX + "px";pixel.style.top = e.pageY + "px";})'''
  9.         driver.execute_script(script)
  10.         ac = ActionChains(driver)
  11.         ac.move_by_offset(1, 0).move_by_offset(-1, 0).perform()
  12.         pixel = driver.find_element(By.ID, 'pixel')
  13.  
  14.     x = pixel.location['x']
  15.     y = pixel.location['y']
  16.  
  17.     if x < 0 or y < 0:
  18.         raise NoCursorCoordinatesException()
  19.  
  20.     return (x, y)
  21. """
  22. Важно переопределять функцию до импорта из HLISA.hlisa_action_chains
  23. """
  24. hlisa_util.get_cursor_coordinates = get_cursor_coordinates_patched
  25.  
  26. from HLISA.hlisa_action_chains import HLISA_ActionChains
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement