From 7bf5fbef4ca9aa4098beac1a1a9ace57684ef6f3 Mon Sep 17 00:00:00 2001 From: Nizar Blass Date: Tue, 28 Apr 2026 23:12:31 +0200 Subject: [PATCH 1/2] fix falsely named function parameter in docstring of Map._to_png --- folium/folium.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/folium/folium.py b/folium/folium.py index aad9fed62a..8d09f60670 100644 --- a/folium/folium.py +++ b/folium/folium.py @@ -368,7 +368,7 @@ def _to_png( Examples -------- >>> m._to_png() - >>> m._to_png(time=10) # Wait 10 seconds between render and snapshot. + >>> m._to_png(delay=10) # Wait 10 seconds between render and snapshot. """ From 8fee45db43057d81d5cf2b6df6d90f72a07812ce Mon Sep 17 00:00:00 2001 From: Nizar Blass Date: Tue, 28 Apr 2026 23:32:26 +0200 Subject: [PATCH 2/2] replace time.sleep() with smarter WebDriverWait() in Map._to_png --- folium/folium.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/folium/folium.py b/folium/folium.py index 8d09f60670..e8c000fa8c 100644 --- a/folium/folium.py +++ b/folium/folium.py @@ -392,11 +392,16 @@ def _to_png( *size, ) driver.set_window_size(*window_size) + from selenium.webdriver.support.ui import WebDriverWait + html = self.get_root().render() with temp_html_filepath(html) as fname: # We need the tempfile to avoid JS security issues. driver.get(f"file:///{fname}") - time.sleep(delay) + WebDriverWait(driver, delay).until( + lambda _driver: _driver.execute_script("return document.readyState") + == "complete" + ) div = driver.find_element("class name", "folium-map") png = div.screenshot_as_png driver.quit()