Starts the chromedriver service that runs in the background and recreates the session.
(self)
| 536 | self._is_connected = False |
| 537 | |
| 538 | def connect(self): |
| 539 | """Starts the chromedriver service that runs in the background |
| 540 | and recreates the session.""" |
| 541 | if hasattr(self, "service"): |
| 542 | with suppress(Exception): |
| 543 | self.service.start() |
| 544 | with suppress(Exception): |
| 545 | already_quit = False |
| 546 | if hasattr(self, "_already_quit") and self._already_quit: |
| 547 | already_quit = True |
| 548 | if not already_quit: |
| 549 | self.start_session() |
| 550 | time.sleep(0.0075) |
| 551 | with suppress(Exception): |
| 552 | for window_handle in self.window_handles: |
| 553 | self.switch_to.window(window_handle) |
| 554 | current_url = None |
| 555 | if hasattr(self, "cdp") and hasattr(self.cdp, "driver"): |
| 556 | with suppress(Exception): |
| 557 | current_url = self.cdp.get_current_url() |
| 558 | if not current_url: |
| 559 | current_url = self.current_url |
| 560 | if current_url.startswith("chrome-extension://"): |
| 561 | # https://issues.chromium.org/issues/396611138 |
| 562 | # (Remove the Linux conditional when resolved) |
| 563 | # (So that close() is always called) |
| 564 | if "linux" in sys.platform: |
| 565 | self.close() |
| 566 | if self.service.is_connectable(): |
| 567 | self.stop_client() |
| 568 | try: |
| 569 | self.service.send_remote_shutdown_command() |
| 570 | except TypeError: |
| 571 | pass |
| 572 | finally: |
| 573 | with suppress(Exception): |
| 574 | self.service._terminate_process() |
| 575 | self.service.start() |
| 576 | self.start_session() |
| 577 | time.sleep(0.003) |
| 578 | with suppress(Exception): |
| 579 | self.switch_to.window(self.window_handles[-1]) |
| 580 | self._is_connected = True |
| 581 | |
| 582 | def start_session(self, capabilities=None): |
| 583 | if not capabilities: |