Код: Выделить всё
##################
browser launched in corect display for
#from pyvirtualdisplay import Display
#display = Display(visible=0, size=(1024, 768))
#display.start()
byt as far i know no way to control mouse actions
################
class DisplayWindow:
def __init__(self, width, height, title):
self.display = Xlib.display.Display()
self.screen = self.display.screen()
# Create window attributes manually
self.attributes = {
"background_pixel": self.screen.white_pixel,
"event_mask": Xlib.X.ExposureMask | Xlib.X.ButtonPressMask,
"border_width": 10,
"depth": self.screen.root_depth,
"class": Xlib.X.InputOutput,
"visual": Xlib.X.CopyFromParent
}
self.window = self.create_window(width, height)
self.set_window_title(title)
def create_window(self, width, height):
return self.screen.root.create_window(
0, 0, # x, y coordinates
width, height, # width, height
**self.attributes # Use dictionary unpacking for attributes
)
def set_window_title(self, title):
self.window.set_wm_name(title)
def launch_display(self):
self.window.map()
self.display.sync()
print(f"Display ID ---->{ self.display.get_display_name()}")
async def drag_and_drop(self, x1, y1, x2, y2):
self.window.warp_pointer(x1, y1)
self.display.sync()
# Simulate left mouse button press
fake_input(self.display, Xlib.X.ButtonPress, 1)
self.display.sync()
# Move the mouse pointer to the ending coordinates
self.window.warp_pointer(x2, y2)
self.display.sync()
# Simulate left mouse button release
fake_input(self.display, Xlib.X.ButtonRelease, 1)
self.display.sync()
###### some coide heare ##########
#display_window.launch_display()
#os.environ['DISPLAY'] = ':0'
#def is_display_available(display_id):
# try:
# display = Xlib.display.Display(display_id)
# return True
# except Xlib.error.DisplayConnectionError:
# return False
#if not is_display_available(':0'):
# print("Virtual display is not available")
# exit(1)
launching asynic browser chrome and making actions
Подробнее здесь: https://stackoverflow.com/questions/790 ... -on-cdp-or