kaliiiiiiiiii / Selenium-Driverless

undetected Selenium without usage of chromedriver
https://kaliiiiiiiiii.github.io/Selenium-Driverless/
Other
412 stars 52 forks source link

add pywin32 functionality such as send_keys click and mouse move #182

Closed FreeM1ne closed 4 months ago

FreeM1ne commented 4 months ago

With pywin32 you can find a window via browser_pid also the advantage of this library is that it can perform actions even in an inactive window.

FreeM1ne commented 4 months ago

and doesn't take the main mouse This implementation will mimic real user input, but will not interfere with other applications in any way, unlike pyautogui.

FreeM1ne commented 4 months ago
import win32gui
import win32process
import win32con
import win32api

import win32gui
import win32con
import win32api
from time import sleep

def click(hwnd, x, y):
    lParam = win32api.MAKELONG(x, y)
    win32api.SendMessage(hwnd, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, lParam)
    sleep(0.05)
    win32api.SendMessage(hwnd, win32con.WM_LBUTTONUP, 0, lParam)

def send_key(hwnd, key):
    if key == "\n":
        win32gui.PostMessage(hwnd, win32con.WM_KEYDOWN, win32con.VK_RETURN, 0)
        win32gui.PostMessage(hwnd, win32con.WM_KEYUP, win32con.VK_RETURN, 0)
    else:
        win32gui.PostMessage(hwnd, win32con.WM_CHAR, ord(key), 0)

def find_window_by_pid(pid): # you can also check the window name
    def callback(hwnd, hwnds):
        _, found_pid = win32process.GetWindowThreadProcessId(hwnd)
        if found_pid == pid:
            hwnds.append(hwnd)
        return True

    hwnds = []
    win32gui.EnumWindows(callback, hwnds)
    return hwnds[0] if hwnds else None
kaliiiiiiiiii commented 4 months ago

ah yep I'm aware of this one. Working with some other guy on that. currently as well. I consider that a part of https://github.com/kaliiiiiiiiii/Selenium-Driverless/issues/94 Therefore closing as dublicate

FreeM1ne commented 4 months ago

The hardest part is figuring out how to interact with elements without driver.find I have three ideas so far 1) open the page, record coordinates and reload it 2) use driver.page_source to find elements and use their coordinates 3) search by images

boludoz commented 3 months ago

Wow, I haven't seen anything so ordinary in years.