* An interface for changing the focus of the driver to another frame or window. * * This class should never be instantiated directly. Instead, obtain an * instance with * * webdriver.switchTo() * * @see WebDriver#switchTo()
| 2369 | * @see WebDriver#switchTo() |
| 2370 | */ |
| 2371 | class TargetLocator { |
| 2372 | /** |
| 2373 | * @param {!WebDriver} driver The parent driver. |
| 2374 | * @private |
| 2375 | */ |
| 2376 | constructor(driver) { |
| 2377 | /** @private {!WebDriver} */ |
| 2378 | this.driver_ = driver |
| 2379 | } |
| 2380 | |
| 2381 | /** |
| 2382 | * Locates the DOM element on the current page that corresponds to |
| 2383 | * `document.activeElement` or `document.body` if the active element is not |
| 2384 | * available. |
| 2385 | * |
| 2386 | * @return {!WebElementPromise} The active element. |
| 2387 | */ |
| 2388 | activeElement() { |
| 2389 | const id = this.driver_.execute(new command.Command(command.Name.GET_ACTIVE_ELEMENT)) |
| 2390 | return new WebElementPromise(this.driver_, id) |
| 2391 | } |
| 2392 | |
| 2393 | /** |
| 2394 | * Switches focus of all future commands to the topmost frame in the current |
| 2395 | * window. |
| 2396 | * |
| 2397 | * @return {!Promise<void>} A promise that will be resolved |
| 2398 | * when the driver has changed focus to the default content. |
| 2399 | */ |
| 2400 | defaultContent() { |
| 2401 | return this.driver_.execute(new command.Command(command.Name.SWITCH_TO_FRAME).setParameter('id', null)) |
| 2402 | } |
| 2403 | |
| 2404 | /** |
| 2405 | * Changes the focus of all future commands to another frame on the page. The |
| 2406 | * target frame may be specified as one of the following: |
| 2407 | * |
| 2408 | * - A number that specifies a (zero-based) index into [window.frames]( |
| 2409 | * https://developer.mozilla.org/en-US/docs/Web/API/Window.frames). |
| 2410 | * - A {@link WebElement} reference, which correspond to a `frame` or `iframe` |
| 2411 | * DOM element. |
| 2412 | * - The `null` value, to select the topmost frame on the page. Passing `null` |
| 2413 | * is the same as calling {@link #defaultContent defaultContent()}. |
| 2414 | * |
| 2415 | * If the specified frame can not be found, the returned promise will be |
| 2416 | * rejected with a {@linkplain error.NoSuchFrameError}. |
| 2417 | * |
| 2418 | * @param {(number|string|WebElement|null)} id The frame locator. |
| 2419 | * @return {!Promise<void>} A promise that will be resolved |
| 2420 | * when the driver has changed focus to the specified frame. |
| 2421 | */ |
| 2422 | frame(id) { |
| 2423 | let frameReference = id |
| 2424 | if (typeof id === 'string') { |
| 2425 | frameReference = this.driver_.findElement({ id }).catch((_) => this.driver_.findElement({ name: id })) |
| 2426 | } |
| 2427 | |
| 2428 | return this.driver_.execute(new command.Command(command.Name.SWITCH_TO_FRAME).setParameter('id', frameReference)) |
nothing calls this directly
no outgoing calls
no test coverage detected