* 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()
| 2495 | * @see WebDriver#switchTo() |
| 2496 | */ |
| 2497 | class TargetLocator { |
| 2498 | /** |
| 2499 | * @param {!WebDriver} driver The parent driver. |
| 2500 | * @private |
| 2501 | */ |
| 2502 | constructor(driver) { |
| 2503 | /** @private {!WebDriver} */ |
| 2504 | this.driver_ = driver |
| 2505 | } |
| 2506 | |
| 2507 | /** |
| 2508 | * Locates the DOM element on the current page that corresponds to |
| 2509 | * `document.activeElement` or `document.body` if the active element is not |
| 2510 | * available. |
| 2511 | * |
| 2512 | * @return {!WebElementPromise} The active element. |
| 2513 | */ |
| 2514 | activeElement() { |
| 2515 | const id = this.driver_.execute(new command.Command(command.Name.GET_ACTIVE_ELEMENT)) |
| 2516 | return new WebElementPromise(this.driver_, id) |
| 2517 | } |
| 2518 | |
| 2519 | /** |
| 2520 | * Switches focus of all future commands to the topmost frame in the current |
| 2521 | * window. |
| 2522 | * |
| 2523 | * @return {!Promise<void>} A promise that will be resolved |
| 2524 | * when the driver has changed focus to the default content. |
| 2525 | */ |
| 2526 | defaultContent() { |
| 2527 | return this.driver_.execute(new command.Command(command.Name.SWITCH_TO_FRAME).setParameter('id', null)) |
| 2528 | } |
| 2529 | |
| 2530 | /** |
| 2531 | * Changes the focus of all future commands to another frame on the page. The |
| 2532 | * target frame may be specified as one of the following: |
| 2533 | * |
| 2534 | * - A number that specifies a (zero-based) index into [window.frames]( |
| 2535 | * https://developer.mozilla.org/en-US/docs/Web/API/Window.frames). |
| 2536 | * - A {@link WebElement} reference, which correspond to a `frame` or `iframe` |
| 2537 | * DOM element. |
| 2538 | * - The `null` value, to select the topmost frame on the page. Passing `null` |
| 2539 | * is the same as calling {@link #defaultContent defaultContent()}. |
| 2540 | * |
| 2541 | * If the specified frame can not be found, the returned promise will be |
| 2542 | * rejected with a {@linkplain error.NoSuchFrameError}. |
| 2543 | * |
| 2544 | * @param {(number|string|WebElement|null)} id The frame locator. |
| 2545 | * @return {!Promise<void>} A promise that will be resolved |
| 2546 | * when the driver has changed focus to the specified frame. |
| 2547 | */ |
| 2548 | frame(id) { |
| 2549 | let frameReference = id |
| 2550 | if (typeof id === 'string') { |
| 2551 | frameReference = this.driver_.findElement({ id }).catch((_) => this.driver_.findElement({ name: id })) |
| 2552 | } |
| 2553 | |
| 2554 | 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