Skip to content

[BUG] - element screenshot is white image #283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
gnori-zon opened this issue Nov 20, 2024 · 0 comments
Open

[BUG] - element screenshot is white image #283

gnori-zon opened this issue Nov 20, 2024 · 0 comments
Labels
bug Something isn't working unconfirmed a bug which hasn't been reproduced yet

Comments

@gnori-zon
Copy link

gnori-zon commented Nov 20, 2024

I wrote a small example,
I'm trying to get screenshots of all the found items,
but they're all white, what am I doing wrong?
Thank you in advance for your help

from selenium_driverless import webdriver
from selenium_driverless.types.by import By
import asyncio

async def test():
    print("start driverless")
    options = webdriver.ChromeOptions()
    async with webdriver.Chrome(options=options) as browser:
        print("start open page")
        try:
            await browser.get('https://hi-tech.mail.ru/', wait_load=True)
        except Exception as ex:
            print("stop wait page by timeout")
        await browser.sleep(0.5)
        try:
            await browser.wait_for_cdp("Page.domContentEventFired", timeout=15)
        except Exception as ex:
            pass
        xpath = "//div[@class='media-ui-slider-list']//div[contains(@class, 'marker-adv-holder')]"
        print("start find by xpath")
        elements = []
        try:
            elements = await browser.find_elements(By.XPATH, xpath)
        except Exception as ex:
            pass
        print(f"founded {len(elements)}")
        count = 0
        for element in elements:
            count = count + 1
            await element.scroll_to()
            await browser.sleep(0.5)
            await browser.execute_script("window.scrollTo(0, 0);")
            await browser.sleep(0.5)
            box = await element.box_model
            x = box["content"][0][0]
            y = box["content"][0][1]
            width = box["width"]
            height = box["height"]
            print({
                "clip": {
                    "x": int(x),
                    "y": int(y),
                    "width": int(width),
                    "height": int(height),
                    "scale": 1
                }
            })
            await element.screenshot(f"screenshot_{count}.png")

        print("finish driverless")

if __name__ == "__main__":
    asyncio.new_event_loop().run_until_complete(test())
@kaliiiiiiiiii kaliiiiiiiiii added bug Something isn't working unconfirmed a bug which hasn't been reproduced yet labels Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working unconfirmed a bug which hasn't been reproduced yet
Projects
None yet
Development

No branches or pull requests

2 participants