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

Function toWireValue

javascript/selenium-webdriver/lib/webdriver.js:150–174  ·  view source on GitHub ↗

* Converts an object to its JSON representation in the WebDriver wire protocol. * When converting values of type object, the following steps will be taken: * * if the object is a WebElement, the return value will be the element's * server ID * if the object defines a {@link Sym

(obj)

Source from the content-addressed store, hash-verified

148 * representation.
149 */
150async function toWireValue(obj) {
151 let value = await Promise.resolve(obj)
152 if (value === void 0 || value === null) {
153 return value
154 }
155
156 if (typeof value === 'boolean' || typeof value === 'number' || typeof value === 'string') {
157 return value
158 }
159
160 if (Array.isArray(value)) {
161 return convertKeys(value)
162 }
163
164 if (typeof value === 'function') {
165 return '' + value
166 }
167
168 if (typeof value[Symbols.serialize] === 'function') {
169 return toWireValue(value[Symbols.serialize]())
170 } else if (typeof value.toJSON === 'function') {
171 return toWireValue(value.toJSON())
172 }
173 return convertKeys(value)
174}
175
176async function convertKeys(obj) {
177 const isArray = Array.isArray(obj)

Callers 3

executeCommandFunction · 0.85
convertKeysFunction · 0.85
executeMethod · 0.85

Calls 3

convertKeysFunction · 0.85
resolveMethod · 0.45
toJSONMethod · 0.45

Tested by

no test coverage detected