Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from selenium.webdriver import ActionChains
- from HLISA.errors import NoCursorCoordinatesException
- def get_cursor_coordinates_patched(driver):
- try:
- pixel = driver.find_element(By.ID, 'pixel')
- except:
- 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";})'''
- driver.execute_script(script)
- ac = ActionChains(driver)
- ac.move_by_offset(1, 0).move_by_offset(-1, 0).perform()
- pixel = driver.find_element(By.ID, 'pixel')
- x = pixel.location['x']
- y = pixel.location['y']
- if x < 0 or y < 0:
- raise NoCursorCoordinatesException()
- return (x, y)
- """
- Важно переопределять функцию до импорта из HLISA.hlisa_action_chains
- """
- hlisa_util.get_cursor_coordinates = get_cursor_coordinates_patched
- from HLISA.hlisa_action_chains import HLISA_ActionChains
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement