Path: blob/trunk/javascript/selenium-webdriver/lib/webelement.js
2884 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617'use strict'18const { isObject } = require('./util')1920/**21* @fileoverview Defines some common methods used for WebElements.22*/2324const LEGACY_ELEMENT_ID_KEY = 'ELEMENT'25const ELEMENT_ID_KEY = 'element-6066-11e4-a52e-4f735466cecf'2627/**28* Contains logic about WebElements.29*/30/**31* @param {?} obj the object to test.32* @return {boolean} whether the object is a valid encoded WebElement ID.33*/34function isId(obj) {35return isObject(obj) && (typeof obj[ELEMENT_ID_KEY] === 'string' || typeof obj[LEGACY_ELEMENT_ID_KEY] === 'string')36}3738/**39* Extracts the encoded WebElement ID from the object.40*41* @param {?} obj The object to extract the ID from.42* @return {string} the extracted ID.43* @throws {TypeError} if the object is not a valid encoded ID.44*/45function extractId(obj) {46if (isObject(obj)) {47if (typeof obj[ELEMENT_ID_KEY] === 'string') {48return obj[ELEMENT_ID_KEY]49} else if (typeof obj[LEGACY_ELEMENT_ID_KEY] === 'string') {50return obj[LEGACY_ELEMENT_ID_KEY]51}52}53throw new TypeError('object is not a WebElement ID')54}5556// PUBLIC API5758module.exports = {59isId,60extractId,61}626364