* Converts a value from its JSON representation according to the WebDriver wire * protocol. Any JSON object that defines a WebElement ID will be decoded to a * WebElement object. All other values will be passed through as is. * * @param {!WebDriver} driver The driver to use as the parent
(driver, value)
| 209 | * @return {*} The converted value. |
| 210 | */ |
| 211 | function fromWireValue(driver, value) { |
| 212 | if (Array.isArray(value)) { |
| 213 | value = value.map((v) => fromWireValue(driver, v)) |
| 214 | } else if (WebElement.isId(value)) { |
| 215 | let id = WebElement.extractId(value) |
| 216 | value = new WebElement(driver, id) |
| 217 | } else if (ShadowRoot.isId(value)) { |
| 218 | let id = ShadowRoot.extractId(value) |
| 219 | value = new ShadowRoot(driver, id) |
| 220 | } else if (isObject(value)) { |
| 221 | let result = {} |
| 222 | for (let key in value) { |
| 223 | if (Object.prototype.hasOwnProperty.call(value, key)) { |
| 224 | result[key] = fromWireValue(driver, value[key]) |
| 225 | } |
| 226 | } |
| 227 | value = result |
| 228 | } |
| 229 | return value |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Resolves a wait message from either a function or a string. |