Search code examples
protractor

Protractor : How to switch to iframe present in second instance of the same test


I have created two chrome instances and in the second chrome instance i am trying to enter card details which is present within iFrame. The below code is giving error.

var browser2 = browser.forkNewDriverInstance(true);
browser2.get('https://test.app.com');
browser2.switchTo().frame(element(by.id("card-number")).getWebElement());

Error:

Failed: stale element reference: element is not attached to the page document

Solution

  • It worked after modifying the code as below,

    browser2.switchTo().frame(browser2.$('#card-number').getWebElement());