DedInc / emunium

A Python module for automating interactions to mimic human behavior in standalone apps or browsers when using Selenium, Pyppeteer, or Playwright. Provides utilities to programmatically move the mouse cursor, click on page elements, type text, and scroll as if performed by a human user.
https://pypi.org/project/emunium/
MIT License
36 stars 4 forks source link

Demo not work for me #8

Closed Jiyr0119 closed 6 days ago

Jiyr0119 commented 1 month ago

python version : 3.12 Minimal reproducible example :https://github.com/Jiyr0119/emunium-demo

DedInc commented 1 month ago

u can pass executable_path to chromium-based browser and maybe will be fixed

import asyncio
from playwright.async_api import async_playwright
from emunium import EmuniumPlaywright

async def main():
    async with async_playwright() as p:
        browser = await p.chromium.launch(
            executable_path=r'C:\Program Files\Google\Chrome\Application\chrome.exe',
            headless=False
        )
        page = await browser.new_page()
        emunium = EmuniumPlaywright(page)

        await page.goto('https://duckduckgo.com/')

        element = await page.wait_for_selector('[data-state="suggesting"]')
        await emunium.type_at(element, 'Automating searches')

        submit = await page.wait_for_selector('[aria-label="Search"]')
        await emunium.click_at(submit)

        await browser.close()

asyncio.run(main())
Jiyr0119 commented 1 month ago

u can pass executable_path to chromium-based browser and maybe will be fixed

import asyncio
from playwright.async_api import async_playwright
from emunium import EmuniumPlaywright

async def main():
    async with async_playwright() as p:
        browser = await p.chromium.launch(
            executable_path=r'C:\Program Files\Google\Chrome\Application\chrome.exe',
            headless=False
        )
        page = await browser.new_page()
        emunium = EmuniumPlaywright(page)

        await page.goto('https://duckduckgo.com/')

        element = await page.wait_for_selector('[data-state="suggesting"]')
        await emunium.type_at(element, 'Automating searches')

        submit = await page.wait_for_selector('[aria-label="Search"]')
        await emunium.click_at(submit)

        await browser.close()

asyncio.run(main())

bro this demo I haven't tried it yet, but the other two have been changed to local paths, but they don't work on mac? Does this have anything to do with the computer system?

Jiyr0119 commented 1 month ago

After I copied your code above, I ran the following error:

Traceback (most recent call last): File "/Users/jonathan/Downloads/mywork/emunium-demo/pldemo.py", line 25, in <module> asyncio.run(main()) File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 194, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 118, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "/Users/jonathan/Downloads/mywork/emunium-demo/pldemo.py", line 18, in main await emunium.type_at(element, 'Automating searches') File "/Users/jonathan/Downloads/mywork/emunium-demo/venv/lib/python3.12/site-packages/emunium/browsers.py", line 123, in type_at center = await self.get_center(element) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jonathan/Downloads/mywork/emunium-demo/venv/lib/python3.12/site-packages/emunium/browsers.py", line 105, in get_center await self._get_browser_properties_if_not_found() File "/Users/jonathan/Downloads/mywork/emunium-demo/venv/lib/python3.12/site-packages/emunium/browsers.py", line 102, in _get_browser_properties_if_not_found await super()._get_browser_properties_if_not_found(screenshot_func) File "/Users/jonathan/Downloads/mywork/emunium-demo/venv/lib/python3.12/site-packages/emunium/base.py", line 70, in _get_browser_properties_if_not_found location = pyautogui.locateOnScreen(temp_screen_path, confidence=0.6) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/jonathan/Downloads/mywork/emunium-demo/venv/lib/python3.12/site-packages/pyautogui/__init__.py", line 174, in wrapper raise ImageNotFoundException # Raise PyAutoGUI's ImageNotFoundException.

Because I am not a professional python developer, I use chatgpt to optimize code in my demo project. What I understand is that the error message is empty when printed。The latest code has been pushed to the demo warehouse. Thank you very much if you can help!!!