title: Testing elements inside unfriendly iframes with PhantomJS
body: <p>Does anyone know if it possible to test for dom elements in unfriendly iframe inside phantomjs? If it is possible, how would someone do that?</p>
  
  <p>I know that we need to set webSecurity to false, but other then that, I dont have any experience with iframes.</p>
  
  <pre><code>'web-security': false
  </code></pre>
  
  <p>Accessing iframes elements:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>"use strict";
  var page = require('webpage').create();
  
  page.open('url', function (status) {
     var _count = page.evaluate(function() {
          var matches = document.querySelectorAll('iframe');
          var count = 0;
          [].forEach.call(matches, function(match) {
              var add = 0;
              try {
                  add = match.contentDocument.querySelectorAll('div').length;
              } catch (x) {
  
              }
              count += add;
          });
  
          return count;
      });
  
      console.log(_count); // 0 - not true
      phantom.exit();
  
  });</code></pre>
  </div>
  </div>
  </p>
  
  <p>Running PhantomJS</p>
  
  <pre><code> npm run phantomjs --web-security=false server/tests/unf.js 
  </code></pre>