Displays a SeleniumBase-generated chart in the browser window. @Params chart_name - If creating multiple charts at the same time, use this to select the one you wish to use. filename - The name of the HTML file that you wish to save the
(self, chart_name=None, filename=None, interval=0)
| 13302 | return file_path |
| 13303 | |
| 13304 | def display_chart(self, chart_name=None, filename=None, interval=0): |
| 13305 | """Displays a SeleniumBase-generated chart in the browser window. |
| 13306 | @Params |
| 13307 | chart_name - If creating multiple charts at the same time, |
| 13308 | use this to select the one you wish to use. |
| 13309 | filename - The name of the HTML file that you wish to |
| 13310 | save the chart to. (filename must end in ".html") |
| 13311 | interval - The delay time for auto-advancing charts. (in seconds) |
| 13312 | If set to 0 (default), auto-advancing is disabled.""" |
| 13313 | if self.headless or self.headless2 or self.xvfb: |
| 13314 | interval = 1 # Race through chart if running in headless mode |
| 13315 | if not chart_name: |
| 13316 | chart_name = "default" |
| 13317 | if not filename: |
| 13318 | filename = "my_chart.html" |
| 13319 | if not interval: |
| 13320 | interval = 0 |
| 13321 | if interval == 0 and self.interval: |
| 13322 | interval = float(self.interval) |
| 13323 | if not isinstance(interval, (int, float)): |
| 13324 | raise Exception('Expecting a numeric value for "interval"!') |
| 13325 | if interval < 0: |
| 13326 | raise Exception('The "interval" cannot be a negative number!') |
| 13327 | if chart_name not in self._chart_data: |
| 13328 | raise Exception("Chart {%s} does not exist!" % chart_name) |
| 13329 | if not filename.endswith(".html"): |
| 13330 | raise Exception('Chart file must end in ".html"!') |
| 13331 | file_path = self.save_chart(chart_name=chart_name, filename=filename) |
| 13332 | self.open_html_file(file_path) |
| 13333 | chart_folder = constants.Charts.SAVED_FOLDER |
| 13334 | if interval == 0: |
| 13335 | with suppress(Exception): |
| 13336 | print("\n*** Close the browser window to continue ***") |
| 13337 | # Will also continue if manually navigating to a new page |
| 13338 | while len(self.driver.window_handles) > 0 and ( |
| 13339 | chart_folder in self.get_current_url() |
| 13340 | ): |
| 13341 | time.sleep(0.05) |
| 13342 | else: |
| 13343 | with suppress(Exception): |
| 13344 | start_ms = time.time() * 1000.0 |
| 13345 | stop_ms = start_ms + (interval * 1000.0) |
| 13346 | for x in range(int(interval * 10)): |
| 13347 | now_ms = time.time() * 1000.0 |
| 13348 | if now_ms >= stop_ms: |
| 13349 | break |
| 13350 | if len(self.driver.window_handles) == 0: |
| 13351 | break |
| 13352 | if chart_folder not in self.get_current_url(): |
| 13353 | break |
| 13354 | time.sleep(0.1) |
| 13355 | |
| 13356 | def extract_chart(self, chart_name=None): |
| 13357 | """Extracts the HTML from a SeleniumBase-generated chart. |