Selenium timed out waiting for chart containers to draw at url #29730
Replies: 3 comments 2 replies
-
Hey there, @jinlinyouyou! 👋 I'm here to assist you with any bugs, questions, or contributions while we wait for a human maintainer. Let's squash those bugs together! To resolve the timeout issue with Selenium while waiting for chart containers to draw, you can increase the wait time for the chart containers to render. This can be done by adjusting the Here is the relevant code snippet that shows how the waits are configured and used: class WebDriverSelenium(WebDriverProxy):
def get_screenshot(self, url: str, element_name: str, user: User) -> bytes | None:
driver = self.auth(user)
driver.set_window_size(*self._window)
driver.get(url)
img: bytes | None = None
selenium_headstart = current_app.config["SCREENSHOT_SELENIUM_HEADSTART"]
logger.debug("Sleeping for %i seconds", selenium_headstart)
sleep(selenium_headstart)
try:
try:
# page didn't load
logger.debug(
"Wait for the presence of %s at url: %s", element_name, url
)
element = WebDriverWait(driver, self._screenshot_locate_wait).until(
EC.presence_of_element_located((By.CLASS_NAME, element_name))
)
except TimeoutException:
logger.exception("Selenium timed out requesting url %s", url)
raise
try:
# chart containers didn't render
logger.debug("Wait for chart containers to draw at url: %s", url)
WebDriverWait(driver, self._screenshot_locate_wait).until(
EC.visibility_of_all_elements_located(
(By.CLASS_NAME, "chart-container")
)
)
except TimeoutException:
logger.exception(
"Selenium timed out waiting for chart containers to draw at url %s",
url,
)
raise
try:
# charts took too long to load
logger.debug(
"Wait for loading element of charts to be gone at url: %s", url
)
WebDriverWait(driver, self._screenshot_load_wait).until_not(
EC.presence_of_all_elements_located((By.CLASS_NAME, "loading"))
)
except TimeoutException:
logger.exception(
"Selenium timed out waiting for charts to load at url %s", url
)
raise
selenium_animation_wait = current_app.config[
"SCREENSHOT_SELENIUM_ANIMATION_WAIT"
]
logger.debug("Wait %i seconds for chart animation", selenium_animation_wait)
sleep(selenium_animation_wait)
logger.debug(
"Taking a PNG screenshot of url %s as user %s",
url,
user.username,
) To increase the wait times, you can modify the current_app.config["SCREENSHOT_LOCATE_WAIT"] = 30 # Increase this value as needed
current_app.config["SCREENSHOT_LOAD_WAIT"] = 60 # Increase this value as needed By increasing these wait times, you give Selenium more time to wait for the chart containers to render and for the charts to load, which should help resolve the timeout issues [1]. |
Beta Was this translation helpful? Give feedback.
-
@jinlinyouyou You can also use the time module to wait while the chart renders, like a wait time 2-5 seconds |
Beta Was this translation helpful? Give feedback.
-
@jinlinyouyou 解决了吗?碰到相同的问题 |
Beta Was this translation helpful? Give feedback.
-
2024-07-28 23:07:50 [2024-07-28 15:07:50,787: ERROR/ForkPoolWorker-7] Selenium timed out waiting for chart containers to draw at url http://superset:8088/superset/dashboard/1/?standalone=3
2024-07-28 23:07:50 Traceback (most recent call last):
2024-07-28 23:07:50 File "/app/superset/utils/webdriver.py", line 378, in get_screenshot
2024-07-28 23:07:50 WebDriverWait(driver, self._screenshot_locate_wait).until(
2024-07-28 23:07:50 File "/usr/local/lib/python3.10/site-packages/selenium/webdriver/support/wait.py", line 80, in until
2024-07-28 23:07:50 raise TimeoutException(message, screen, stacktrace)
2024-07-28 23:07:50 selenium.common.exceptions.TimeoutException: Message:
2024-07-28 23:07:50
2024-07-28 23:07:52 [2024-07-28 15:07:52,259: INFO/ForkPoolWorker-7] Task cache_dashboard_thumbnail[9d3c2f15-c6b7-43f3-a68d-021c01025b6b] succeeded in 116.81248734199835s: None
Beta Was this translation helpful? Give feedback.
All reactions