How do I access an iframe from CasperJS?

后端 未结 5 1770
情书的邮戳
情书的邮戳 2020-11-29 04:33

I have a webpage with an iframe. I\'d like to access the contents of the iframe using CasperJS. In particular, I need to click buttons and fill a form. How can I do that?

5条回答
  •  甜味超标
    2020-11-29 05:00

    Suppose we have different frames(frame1 and frame2) and we have to access different elements(like click or check if div tag exits or not) of those frames.

    casper.withFrame('frame1', function() {
        var file = '//*[@id="profile_file"]';
        casper.thenClick(x(file));
    });
    
    casper.withFrame('frame2', function() {
      casper.then(function () {
         casper.waitForSelector('#pageDIV',
                function pass() {
                    console.log("pass");
                },
                function fail(){
                    console.log("fail");
                }
          );
       });
    });
    

提交回复
热议问题