To switch to an Iframe in Protractor, there is a method to serve the purpose. Use switchTo().frame() method to switch focus to Iframe. To get back the focus from Iframe to Angular paga, use switchTo().defaultContent() method.
Below is the sample code to explain this case. Assuming there is an Iframe and need to click an element in Iframe. Once the element is clicked, Iframe disappears automatically, then swith the focus to Angular page.
browser.driver.switchTo().frame('Frame');
browser.driver.findElement(By.className("insert-btn")).click();
browser.switchTo().defaultContent().then(function() {
var elm=element.all(by.repeater('data in Data.items')).filter(function(elem, index) {
return elem.getText().then(function(text) {
return (text.indexOf("HTML")>-1);
});
}).then(function(filteredElements){
filteredElements[0].click();
});
});
Below is the sample code to explain this case. Assuming there is an Iframe and need to click an element in Iframe. Once the element is clicked, Iframe disappears automatically, then swith the focus to Angular page.
browser.driver.switchTo().frame('Frame');
browser.driver.findElement(By.className("insert-btn")).click();
browser.switchTo().defaultContent().then(function() {
var elm=element.all(by.repeater('data in Data.items')).filter(function(elem, index) {
return elem.getText().then(function(text) {
return (text.indexOf("HTML")>-1);
});
}).then(function(filteredElements){
filteredElements[0].click();
});
});