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

Method start_devtools

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

Source from the content-addressed store, hash-verified

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