kaliiiiiiiiii / Selenium-Driverless

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

[Error] Screenshot error #266

Closed Toxenskiy closed 2 months ago

Toxenskiy commented 2 months ago

I open my browser and there's a tab open by default.

Traceback (most recent call last):
  File "C:\Users\OP\AppData\Local\Programs\Python\Python311\Lib\asyncio\tasks.py", line 490, in wait_for
    return fut.result()
           ^^^^^^^^^^^^
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\OP\AppData\Local\Programs\Python\Python311\Lib\site-packages\cdp_socket\socket.py", line 77, in exec
    res = await asyncio.wait_for(self._responses[_id], timeout=timeout)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\OP\AppData\Local\Programs\Python\Python311\Lib\asyncio\tasks.py", line 492, in wait_for
    raise exceptions.TimeoutError() from exc
TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\OP\Desktop\check_geo.py", line 40, in <module>
    screenshot = driver.get_screenshot_as_base64()
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\OP\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium_driverless\sync\webdriver.py", line 35, in syncified
    return self._loop.run_until_complete(res(*args, **kwargs))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\OP\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\OP\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium_driverless\webdriver.py", line 1105, in get_screenshot_as_base64
    return await self.current_target.get_screenshot_as_base64()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\OP\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium_driverless\types\target.py", line 843, in get_screenshot_as_base64
    res = await self.execute_cdp_cmd("Page.captureScreenshot", {"format": "png"}, timeout=30)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\OP\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium_driverless\types\target.py", line 935, in execute_cdp_cmd
    result = await self.socket.exec(method=cmd, params=cmd_args, timeout=timeout)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\OP\AppData\Local\Programs\Python\Python311\Lib\site-packages\cdp_socket\socket.py", line 93, in exec
    raise SocketExcitedError("socket coroutine excited without exception")
cdp_socket.exceptions.SocketExcitedError: socket coroutine excited without exception
options.user_data_dir = False
options._startup_url = None

with webdriver.Chrome(options=options) as driver:
  sync_input = SyncInput(browser=driver)
  driver.clear_proxy()
  time.sleep(3)
  driver.refresh()
  time.sleep(15)
  screenshot = driver.get_screenshot_as_base64()
  save_base64_image(screenshot)
Toxenskiy commented 2 months ago

If I open a new empty tab, the screenshot is taken without a problem

kaliiiiiiiiii commented 2 months ago

Sync is buggy, not recommended and is currently not expected to work without any issues - closing for now. I'm pretty sure this works with async just fine.

If that is not the case, feel free to let me know.