MCPcopy Index your code
hub / github.com/SeleniumHQ/selenium / ableToSwitchToFrame

Function ableToSwitchToFrame

javascript/selenium-webdriver/lib/until.js:70–102  ·  view source on GitHub ↗

* Creates a condition that will wait until the input driver is able to switch * to the designated frame. The target frame may be specified as * * 1. a numeric index into * [window.frames](https://developer.mozilla.org/en-US/docs/Web/API/Window.frames) * for the currently selected frame.

(frame)

Source from the content-addressed store, hash-verified

68 * @return {!Condition<boolean>} A new condition.
69 */
70function ableToSwitchToFrame(frame) {
71 let condition
72 if (typeof frame === 'number' || frame instanceof webdriver.WebElement) {
73 condition = (driver) => attemptToSwitchFrames(driver, frame)
74 } else {
75 condition = function (driver) {
76 let locator = /** @type {!(By|Function)} */ (frame)
77 return driver.findElements(locator).then(function (els) {
78 if (els.length) {
79 return attemptToSwitchFrames(driver, els[0])
80 }
81 })
82 }
83 }
84
85 return new Condition('to be able to switch to frame', condition)
86
87 function attemptToSwitchFrames(driver, frame) {
88 return driver
89 .switchTo()
90 .frame(frame)
91 .then(
92 function () {
93 return true
94 },
95 function (e) {
96 if (!(e instanceof error.NoSuchFrameError)) {
97 throw e
98 }
99 },
100 )
101 }
102}
103
104/**
105 * Creates a condition that waits for an alert to be opened. Upon success, the

Callers

nothing calls this directly

Calls 2

attemptToSwitchFramesFunction · 0.85
findElementsMethod · 0.65

Tested by

no test coverage detected