मेरे पास एक आईफ्रेम वाला वेबपृष्ठ है। मैं CasperJS का उपयोग कर आईफ्रेम की सामग्री तक पहुंच बनाना चाहता हूं। विशेष रूप से, मुझे बटन क्लिक करने और एक फॉर्म भरने की आवश्यकता है। मैं उसे कैसे कर सकता हूँ?मैं कैस्परजेएस से आईफ्रेम कैसे प्राप्त करूं?
मुख्य वेबपेज main.html है:
<html><body>
<a id='main-a' href="javascript:console.log('pressed main-a');">main-a</a>
<iframe src="iframe.html"></iframe>
<a id='main-b' href="javascript:console.log('pressed main-b');">main-b</a>
</body></html>
आइफ्रेम है:
<html><body>
<a id='iframe-c' href="javascript:console.log('pressed iframe-c');">iframe-c</a>
</body></html>
मेरे भोली दृष्टिकोण:
var casper = require('casper').create({
verbose: true,
logLevel: "debug"
});
casper.start("http://jim.sh/~jim/tmp/casper/main.html", function() {
this.click('a#main-a');
this.click('a#main-b');
this.click('a#iframe-c');
});
casper.run(function() {
this.exit();
});
काम नहीं करता, ज़ाहिर है, क्योंकि a#iframe-c
चयनकर्ता मुख्य फ्रेम में मान्य नहीं है:
[info] [phantom] Starting...
[info] [phantom] Running suite: 2 steps
[debug] [phantom] opening url: http://jim.sh/~jim/tmp/casper/main.html, HTTP GET
[debug] [phantom] Navigation requested: url=http://jim.sh/~jim/tmp/casper/main.html, type=Other, lock=true, isMainFrame=true
[debug] [phantom] url changed to "http://jim.sh/~jim/tmp/casper/main.html"
[debug] [phantom] Navigation requested: url=http://jim.sh/~jim/tmp/casper/iframe.html, type=Other, lock=true, isMainFrame=false
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step 2/2 http://jim.sh/~jim/tmp/casper/main.html (HTTP 200)
[debug] [phantom] Mouse event 'click' on selector: a#main-a
[info] [remote] pressed main-a
[debug] [phantom] Mouse event 'click' on selector: a#main-b
[info] [remote] pressed main-b
[debug] [phantom] Mouse event 'click' on selector: a#iframe-c
FAIL CasperError: Cannot dispatch click event on nonexistent selector: a#iframe-c
# type: uncaughtError
# error: "CasperError: Cannot dispatch click event on nonexistent selector: a#iframe-c"
CasperError: Cannot dispatch click event on nonexistent selector: a#iframe-c
/tmp:901 in mouseEvent
/tmp:365 in click
/tmp/test.js:9
/tmp:1103 in runStep
/tmp:324 in checkStep
क्या यह काम करने का कोई तरीका है? एक हैक जिसमें फांटोमज में सीधे पोकिंग करना शामिल होगा, ठीक है, लेकिन मुझे नहीं पता कि वहां क्या करना है।
मैं CasperJS संस्करण 1.0.0-RC1 और phantomjs संस्करण 1.6.0 का उपयोग कर रहा हूं।
जिम, क्या आपको यह पता चल गया कि क्या आप स्विचिंग के बाद यह.test.assertVisible ('# someElemInsideIframe') कर सकते हैं? मेरे लिए बार्फ़ लगता है लेकिन यह .click (...) काम करता है। –
मुझे नहीं, क्षमा करें। दृश्यता का परीक्षण किसी अन्य तरीके से किया जा सकता है जो फ्रेम के साथ अच्छी तरह से काम नहीं करता है, मुझे यकीन नहीं है। –
क्या आप @ olleolleolle का जवाब देखा था? withframe एक दस्तावेज विधि है। –