I have a webpage that displays an iframe, within the iframe there is a spinning spinner (overlying the fields).
My approach involves using selenium to navigate to the iframe,
return this.driver.wait(function() {
return self.webdriver.until.ableToSwitchToFrame(self.driver.findElement(self.page.loginIframe.selector))
}, this.config.driver.defaultTimeout);
following which I call this.driver.switchTo().frame(0);
once the above condition is satisfied
however, I need to ensure that the spinner disappears and the input fields are ready for data entry.
If I utilize a driver.sleep
, I can successfully input data, but if I attempt to use .elementIsVisible, it promptly tries to input data and fails.
snippet for logging in:
var self = this;
this.waitForPageLoad().then(function pageLoaded() {
console.log("page loaded");
self.switchToIframe().then(function switchedToIframe() {
console.log("switched to iframe");
// THIS FIXES the issue, but I do not want a random sleep self.driver.sleep(10000);
self.waitForIframeLoad().then(function iframeLoaded() {
console.log("iframe loaded!");
self.setUserName(self.config.user.userName);//FAILS HERE
});
});
});
snippet that triggers an error:
Login.prototype.waitForIframeLoad = function() {
var self = this;
//console.log(self.webdriver.until);
return this.driver.wait(function() {
return self.webdriver.until.elementIsVisible(self.driver.findElement(self.page.usernameInputField.selector))
}, this.config.driver.defaultTimeout);
};
error message:
NoSuchElementError: no such element