Can phantomjs perform actions like getText() or enterText() inside iFrame? I am using protractor to do my testing. Phantomjs can perform actions in the default frame but inside iframe the locators get timed out. Any suggestions?
Asked
Active
Viewed 1,062 times
2
2 Answers
5
You need to switch to the iframe before you can use it. Like so...
browser.switchTo().frame(iframeNameOrIndex);
Then to switch back, you use:
browser.driver.switchTo().defaultContent();
The Protractor API is a good source for this...
Also, if the iframe is from another domain you may need to add the --web-security=no
option for phantomjs:
phantomjs --web-security=no spec.js

Brine
- 3,733
- 1
- 21
- 38
-
1yes this works fine with any other browser. Just with phantomjs i am facing the issue. It is successfuly switching frames even but inside the iframe it is not being able to locate the web elements. Maybe i am missing something, still trying to debug. – KBM Aug 20 '15 at 13:44
-
@Mainak try adding explicit waits with [`browser.wait`](http://angular.github.io/protractor/#/api?view=webdriver.WebDriver.prototype.wait) and expected conditions. – alecxe Aug 20 '15 at 16:04
-
Loading is almost always problem with PhanotmJS. Try to wait for 10 seconds, and then try to access elements in iframe. If it is not working, make screenshot with PhantomJS, and see weather iframe is loading. – MrD Aug 21 '15 at 09:42
-
No good still. Checked the screenshot, the iframe was loaded and also ran in debug mode, where the switch to frame passed but failed when did a find element/ wait for a condition. Any leads on how to implement htmlunit driver with protractor? It can be used instead of phantomjs as well right? – KBM Aug 24 '15 at 08:49
-
Is your iFrame on a different domain? try using the `--web-security=no` option. I updated my answer with this too. – Brine Aug 24 '15 at 12:17
-
@Brine already done that. Using the following 'phantomjs.cli.args': ['--web-security=false', '--ssl-protocol=tlsv1', '--ignore-ssl-errors=yes', '--webdriver-loglevel=DEBUG'] – KBM Aug 24 '15 at 13:08
0
Yes.. First, double-check the name of the id of the iframes using console.log(page.childFramesName());
.. Next, you can switch the page to the iframe using page.switchToChildFrame('name_here');
. Finally, you can do whatever you want.

Bla...
- 7,228
- 7
- 27
- 46