HENNGE / arsenic

Async WebDriver implementation for asyncio and asyncio-compatible frameworks
Other
350 stars 53 forks source link

Selenium-like Element screenshot #60

Closed Silverdoses closed 3 years ago

Silverdoses commented 5 years ago

Selenium WebElements implements 3 properties called screenshot_as_base64, screenshot_as_png and screenshot.

Arsenic has those functions in its session.py implementation, but it can only takes a screenshot to the browser visible content. We can't simply take a screenshot of a desired element. So this new method get_screenshot for the class Element solves the pain of doing the steps of locating and cropping for each one of them.

Proof of concept:


import asyncio
from arsenic import get_session, browsers, services

async def hello_world():
    service = services.Chromedriver()
    browser = browsers.Chrome())
    async with get_session(service, browser) as session:
        await session.get('https://www.google.com')
        logo = await session.wait_for_element(5, 'img[id=hplogo]')
        img = await logo.get_screenshot()

        with open('screenshot.png', 'wb') as png:
            png.write(img.read())

def main():
    loop = asyncio.get_event_loop()
    loop.run_until_complete(hello_world())

if __name__ == '__main__':
    main()

Result: screenshot

NotoriousRebel commented 4 years ago

Any updates on this?

Silverdoses commented 4 years ago

I don't know. Unfortunately, this repo seems abandoned.

dimaqq commented 4 years ago

The repo is not abandoned, rather:

ojii commented 3 years ago

merged in #97