Path: blob/trunk/javascript/selenium-webdriver/test/stale_element_test.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'1819const assert = require('node:assert')20const test = require('../lib/test')21const { Browser, By, error, until } = require('selenium-webdriver')22const Pages = test.Pages2324test.suite(function (env) {25var driver26before(async function () {27driver = await env.builder().build()28})29after(function () {30return driver.quit()31})3233// Element never goes stale in Safari.34test35.ignore(env.browsers(Browser.SAFARI))36.it('dynamically removing elements from the DOM trigger a ' + 'StaleElementReferenceError', async function () {37await driver.get(Pages.javascriptPage)3839var toBeDeleted = await driver.findElement(By.id('deleted'))40assert.strictEqual(await toBeDeleted.getTagName(), 'p')4142await driver.findElement(By.id('delete')).click()43await driver.wait(until.stalenessOf(toBeDeleted), 5000)44})4546it('an element found in a different frame is stale', async function () {47await driver.get(Pages.missedJsReferencePage)4849var frame = await driver.findElement(By.css('iframe[name="inner"]'))50await driver.switchTo().frame(frame)5152var el = await driver.findElement(By.id('oneline'))53await driver.switchTo().defaultContent()54return el.getText().then(assert.fail, function (e) {55assert.ok(e instanceof error.NoSuchElementError)56})57})58})596061