MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / start_devtools

Method start_devtools

py/selenium/webdriver/remote/webdriver.py:1145–1182  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1143 raise WebDriverException("You can only set the orientation to 'LANDSCAPE' and 'PORTRAIT'")
1144
1145 def start_devtools(self) -> tuple[Any, WebSocketConnection]:
1146 global cdp
1147 import_cdp()
1148 if self.caps.get("se:cdp"):
1149 ws_url = self.caps.get("se:cdp")
1150 cdp_version = self.caps.get("se:cdpVersion")
1151 if cdp_version is None:
1152 raise WebDriverException("CDP version not found in capabilities")
1153 version = cdp_version.split(".")[0]
1154 else:
1155 version, ws_url = self._get_cdp_details()
1156
1157 if not ws_url:
1158 raise WebDriverException("Unable to find url to connect to from capabilities")
1159
1160 if cdp is None:
1161 raise WebDriverException("CDP module not loaded")
1162
1163 self._devtools = cdp.import_devtools(version)
1164 if self._websocket_connection:
1165 return self._devtools, self._websocket_connection
1166 if self.caps["browserName"].lower() == "firefox":
1167 raise RuntimeError("CDP support for Firefox has been removed. Please switch to WebDriver BiDi.")
1168 if not isinstance(self.command_executor, RemoteConnection):
1169 raise WebDriverException("command_executor must be a RemoteConnection instance for CDP support")
1170 self._websocket_connection = WebSocketConnection(
1171 ws_url,
1172 self.command_executor.client_config.websocket_timeout,
1173 self.command_executor.client_config.websocket_interval,
1174 )
1175 targets = self._websocket_connection.execute(self._devtools.target.get_targets())
1176 for target in targets:
1177 if target.target_id == self.current_window_handle:
1178 target_id = target.target_id
1179 break
1180 session = self._websocket_connection.execute(self._devtools.target.attach_to_target(target_id, True))
1181 self._websocket_connection.session_id = session
1182 return self._devtools, self._websocket_connection
1183
1184 @asynccontextmanager
1185 async def bidi_connection(self):

Callers 2

test_check_start_twiceFunction · 0.80

Calls 7

_get_cdp_detailsMethod · 0.95
WebDriverExceptionClass · 0.90
WebSocketConnectionClass · 0.90
splitMethod · 0.80
import_cdpFunction · 0.70
getMethod · 0.65
executeMethod · 0.65

Tested by 2

test_check_start_twiceFunction · 0.64