Protractor testing in iframe in other non-Angular

2019-07-21 00:38发布

问题:

My application is integrated with other site. That integration is established by clicking on the button. When I click on the button, pop-up shows with html that comes from another site. I show that content using this by putting URL in iframe. Url is from external site:

<iframe class='' ng-src="{{url}}"></iframe>

Can I execute my protractor test on elements on that pop-up?

When I try to access to element on pop-up by ID, it says No such element found. I got IDs of elements by Firebug tool on Firefox. I hit this, and it returns me false:

expect(element(by.id('**id of element in pop-up**')).isDisplayed()).toBe(true);

Can someone help me with this? Is it possible to run Protractor tests and on this kind of html?

回答1:

You need to switch context to iframe. You can do that by adding these lines of code:

var driver = ptor.driver;
ptor.switchTo().frame(driver.findElement(protractor.By.tagName('iframe')));

Try to access your elements in pop-up now?