-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interacting with elements inside an iframe #203
Comments
EDIT: This doesn't work anymore on 2.0 and above, scroll all the way down for the new solutions. I had to create a exports.withFrame = function(frameSelector, fn, done){
// `frameSelector` is either an index number or the iframe's name
// no class names or ids unfortunately
// As you can see, the code is identical to that of the `use` function
debug('.withFrame():' + frameSelector);
this.page.switchToFrame(frameSelector);
var cache = this.queue;
this.queue = [];
fn(this);
var self = this;
this.queue = this.queue.concat(cache);
done();
};
exports.backToParentFrame = function(done){
debug('.backToParentFrame()');
this.page.switchToParentFrame();
done();
}; I originally tried to make it so that once the actions inside <!-- For this given iframe -->
<iframe name="formIframe" src="somelogin.php" /> nightmare
.withFrame('formIframe', function (nightmare) {
nightmare
.wait('form#login')
.type('#username', 'rclai')
.type('#password', 'password')
.click('#submit')
})
.backToParentFrame()
.wait('.for-my-logged-in-indicator')
.run(...); Don't know if you guys want to include this functionality or not. I've taken the concept from CasperJS here. If you guys like it, I would suggest figuring out how we can automatically go back to the parent frame without explicitly having to do so. |
Nice feature +1 |
Where would this be added @rclai please? |
You should be able to copy and paste the code I typed above and put it into |
Sweet, thanks! |
+1 |
Thanks @rclai I've created a plugin from your code: https://www.npmjs.com/package/nightmare-iframe |
Cool. |
The above PR allows you to do var result = yield nightmare
.evaluate(function () {
return $("#id_description_iframe").contents().find("body").html();
}); |
Thank you for the feature! TypeError: Cannot read property 'switchToFrame' of undefined
at Nightmare.exports.withFrame (/var/www/html/antiqode/node_modules/nightmare/lib/actions.js:439:12)
at Nightmare.next (/var/www/html/antiqode/node_modules/nightmare/lib/nightmare.js:144:12)
at EventEmitter.<anonymous> (/var/www/html/antiqode/node_modules/nightmare/lib/nightmare.js:150:12)
at EventEmitter.g (events.js:260:16)
at emitNone (events.js:67:13)
at EventEmitter.emit (events.js:166:7)
at ChildProcess.<anonymous> (/var/www/html/antiqode/node_modules/nightmare/lib/ipc.js:28:10)
at emitTwo (events.js:87:13)
at ChildProcess.emit (events.js:172:7)
at handleMessage (internal/child_process.js:686:10) I tried to install the plugin npm install --save nightmare-iframe $ phantomjs -v
2.0.1-development
$ node -v
v4.2.2 |
I tried the change preferences solution but could not change elements (type, etc) inside the iframe, just extract info. And the first solution does not work for me as the iframes in my problem only have ids. Any ideas? |
So, how can we navigate through iframes with the new Nightmare built on Electron? It seems Electron has no support for iframes. |
I just submitted a PR (#496) that should solve this issue. If you have the time you may check it to see if it works. An example of the usage would be:
It would print to the console:
Also, it should work with general selectors, not just with iframe names or numbers. |
Hello. I'm trying to enter a credit card number in an iframe and I'm not sure which of the methods to use:
Please can someone tell me which is best? This issue has too many options. PS. I'm using Electron, I see references above to phantom.js which confuse me even more, because I thought that was for Nightwatch, not Nightmare. |
More Googling shows me there isn't a solution to this problem. Please will whoever runs this project add a sentence to the main readme.md stating that nightmare doesn't support iframes. We wouldn't have tried to learnt this framework if we knew it couldn't handle iframes. Their supoprt is absolutely essential to test any website that does ecommerce. |
@RichardJECooke here's the summary.
Right now, the best you can do is use @rosshinkley's https://github.com/rosshinkley/nightmare-iframe-manager. Go there and check his documentation. That's what I'm doing. The Nightmare team (Segmentio) don't like the approach taken in the PR and the plug-in (not even Ross, the plug-in's writer). They dislike it so much that didn't wan to publish it to NPM, you have to install it from GitHub. Feel yourself hyper-warned. No warranties anywhere, use at your own risk, etc. Given that, for non-mission critical problems (to emphasize the warnings) the plug-in works pretty good. I use it to extract my credit card transactions in my bank's website. Here's what you would do (excessively detailed):
mkdir myProject
cd myProject
npm init
npm install --save rosshinkley/nightmare-iframe-manager
var Nightmare = require('nightmare');
require('nightmare-iframe-manager')(Nightmare);
|
Sadly this doesn't work for me, I get:
when calling import Nightmare = require('nightmare');
const show = (process.env.ekaya_gumtree_test_show_browser_window === 'true');
export const nightmare = new Nightmare({'show': show, 'height': 900 });
import manageNightmareIframesPlugin = require('nightmare-iframe-manager');
manageNightmareIframesPlugin(nightmare); |
You are modifying the I bet it would be something like: import Nightmare = require('nightmare');
import manageNightmareIframesPlugin = require('nightmare-iframe-manager');
manageNightmareIframesPlugin(Nightmare);
const show = (process.env.ekaya_gumtree_test_show_browser_window === 'true');
export const nightmare = new Nightmare({'show': show, 'height': 900 }); |
Thank you for summary ! This could work for me. For different domain iframe,
is needed, seems. ( Otherwise, an error
will occur. I hope this can help someone. |
I'm getting errors when using Kind of a bummer, as I was hoping to use nightmare as part of a build on our Jenkins server (Ubuntu server 16.06). |
@RoyTinker you should probably move to https://github.com/GoogleChrome/puppeteer . It is made by the GoogleChrome team directly, uses Chrome headless and has official support for iframes. It was released about a month ago or so, and the GitHub stars count is already over 9000. |
OMG! Well that's a nightmare! It was doing so well until the Iframe :( |
Ok, moved to puppeteer, it's working great! A few gotchas in automation, but it's good now. |
Is this possible?
EDIT: You should probably just use Puppeteer.
The text was updated successfully, but these errors were encountered: