Skip to content
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

Switch To Frame #42

Closed
JarrodCTaylor opened this issue Jul 28, 2017 · 2 comments
Closed

Switch To Frame #42

JarrodCTaylor opened this issue Jul 28, 2017 · 2 comments

Comments

@JarrodCTaylor
Copy link

I am needing to interact with the contents of an iframe, and so far coming up short in my attempts. Does the devtools-protocol have anything analogous to https://w3c.github.io/webdriver/webdriver-spec.html#switch-to-frame or is there an alternative way to accomplish that interaction?

@kensoh
Copy link

kensoh commented Aug 6, 2017

I'm not aware of that, for me I set the frame context by defining this way -
frame_context = document.evaluate('(//frame|//iframe)[@name="'+frameInfo+'" or @id="'+frameInfo+'"]',document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotItem(0).contentDocument;

Then perform subsequent interactions with CSS selector -
frame_context.querySelector()...

Or with XPath selector -
document.evaluate(selector,frame_context,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotItem(0)...

The Chromy project based on chrome-remote-interface also has an implementation for iframe - https://github.com/OnetapInc/chromy/blob/e0cfc3038349d0bf2bc0e452806ac7f2b5ba7cc0/src/document.js#L34

@paulirish
Copy link
Member

@JarrodCTaylor take a look at https://github.com/GoogleChrome/puppeteer/blob/master/lib/FrameManager.js

Basically you can listen to Page.frameAttached, Runtime.executionContextCreated etc events..
Then you can do a Runtime.evaluate using the new contextId param.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants