1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Is there way to inject mouse actions inside a browser with no relying on cdp or js or...

Discussão em 'Python' iniciado por Stack, Outubro 1, 2024 às 12:42.

  1. Stack

    Stack Membro Participativo

    hi is there way to make mouse actions drag and drop for browser with no relying on cdp or js or sys wide solusions also besides my solution fails cause of browser instance not launching inside of vd



    ##################
    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




    i tried js injection failed cause of same origin policy tried pyautogui failed not suitable for task tried selenium methods failed cause of detection of cdp and many more

    Continue reading...

Compartilhe esta Página