1

I know this has been asked multiple times, and the suggested solution has been to use something like browser.driver.switchTo('your-frame-name') but I can't seem to access the same switchTo() method in my code.

This is my test :

import { AppPage } from './app.po';
import {browser, by, element} from 'protractor';

describe('angular-test App', () => {
  let page: AppPage;

  beforeEach(() => {
    page = new AppPage();
  });

  it('should display welcome message', () => {
    page.navigateTo();
    browser.driver.switchToParentFrame()

    //expect(page.getParagraphText()).toEqual('Welcome to app!');
    expect(element(by.id('myHeader')).getText()).toEqual('Welcome to Angular Test App!  ');
  });
});

switchToParentFrame() is the only available method I get after the browser.driver.

This is how my HTML looks like

enter image description here

Any help is appreaciated, sorry for the vague description of the question but I'm pretty new to coding/protractor e2e testing.

fOcusWow
  • 383
  • 1
  • 5
  • 14
  • 2
    A good start would be to have a look at the API: http://www.protractortest.org/#/api?view=webdriver.WebDriver.prototype.switchTo – Florent B. Nov 30 '17 at 23:12
  • Possible duplicate of [Protractor: Testing Angular App in an Iframe](https://stackoverflow.com/questions/20425909/protractor-testing-angular-app-in-an-iframe) – Andersson Dec 01 '17 at 05:40
  • Are you using the latest version of protractor? – HaC Dec 03 '17 at 05:43

3 Answers3

4
browser.switchTo().frame(element(by.tagName('iframe')).getWebElement());
fOcusWow
  • 383
  • 1
  • 5
  • 14
1
var elem = element(by.xpath('iframe element')); // .//div[contains(@id,\'cke\')]/iframe   
browser.sleep(3000);
elem.click();    
browser.switchTo().frame(elem.getWebElement());    
browser.sleep(3000);    
element(by.tagName('body')).sendKeys('test');     
browser.switchTo().defaultContent();    
browser.sleep(3000);
0
 browser.switchTo().activeElement();

or try to experiment with other available methods

andriyze
  • 464
  • 3
  • 7