Activate CDP Mode with the URL and kwargs.
(self, url=None, **kwargs)
| 5067 | self.execute_script(script) |
| 5068 | |
| 5069 | def activate_cdp_mode(self, url=None, **kwargs): |
| 5070 | """Activate CDP Mode with the URL and kwargs.""" |
| 5071 | if getattr(self.driver, "_is_using_uc", None): |
| 5072 | if self.__is_cdp_swap_needed(): |
| 5073 | if url: |
| 5074 | self.cdp.open(url, **kwargs) |
| 5075 | return # CDP Mode is already active |
| 5076 | if not self.is_connected(): |
| 5077 | self.driver.connect() |
| 5078 | current_url = self.get_current_url() |
| 5079 | if not current_url.startswith(("about", "data", "chrome")): |
| 5080 | self.driver.get("about:blank") |
| 5081 | self.driver.uc_open_with_cdp_mode(url, **kwargs) |
| 5082 | else: |
| 5083 | self.get_new_driver(undetectable=True) |
| 5084 | if self.browser == "edge": |
| 5085 | raise Exception( |
| 5086 | 'For stealth with Edge, use "Pure CDP Mode"! Eg:\n' |
| 5087 | '```python\n' |
| 5088 | 'from seleniumbase import sb_cdp\n' |
| 5089 | 'sb = sb_cdp.Chrome(url, browser="edge")\n' |
| 5090 | '```' |
| 5091 | ) |
| 5092 | self.driver.uc_open_with_cdp_mode(url, **kwargs) |
| 5093 | self.cdp = self.driver.cdp |
| 5094 | if hasattr(self.cdp, "solve_captcha"): |
| 5095 | self.solve_captcha = self.cdp.solve_captcha |
| 5096 | if hasattr(self.cdp, "click_captcha"): |
| 5097 | self.click_captcha = self.cdp.click_captcha |
| 5098 | if hasattr(self.cdp, "add_handler"): |
| 5099 | self.add_handler = self.cdp.add_handler |
| 5100 | if hasattr(self.cdp, "close_active_tab"): |
| 5101 | self.close_active_tab = self.cdp.close_active_tab |
| 5102 | if hasattr(self.cdp, "find_element_by_text"): |
| 5103 | self.find_element_by_text = self.cdp.find_element_by_text |
| 5104 | if hasattr(self.cdp, "find_elements_by_text"): |
| 5105 | self.find_elements_by_text = self.cdp.find_elements_by_text |
| 5106 | if hasattr(self.cdp, "get_active_tab"): |
| 5107 | self.get_active_tab = self.cdp.get_active_tab |
| 5108 | if hasattr(self.cdp, "get_all_cookies"): |
| 5109 | self.get_all_cookies = self.cdp.get_all_cookies |
| 5110 | if hasattr(self.cdp, "get_all_urls"): |
| 5111 | self.get_all_urls = self.cdp.get_all_urls |
| 5112 | if hasattr(self.cdp, "get_document"): |
| 5113 | self.get_document = self.cdp.get_document |
| 5114 | if hasattr(self.cdp, "get_element_attribute"): |
| 5115 | self.get_element_attribute = self.cdp.get_element_attribute |
| 5116 | if hasattr(self.cdp, "get_element_attributes"): |
| 5117 | self.get_element_attributes = self.cdp.get_element_attributes |
| 5118 | if hasattr(self.cdp, "get_element_html"): |
| 5119 | self.get_element_html = self.cdp.get_element_html |
| 5120 | if hasattr(self.cdp, "get_endpoint_url"): |
| 5121 | self.get_endpoint_url = self.cdp.get_endpoint_url |
| 5122 | if hasattr(self.cdp, "get_event_loop"): |
| 5123 | self.get_event_loop = self.cdp.get_event_loop |
| 5124 | if hasattr(self.cdp, "get_flattened_document"): |
| 5125 | self.get_flattened_document = self.cdp.get_flattened_document |
| 5126 | if hasattr(self.cdp, "get_navigation_history"): |
no test coverage detected