title: Login form in iframe from AliExpress doesn't work in PhantomJS
body: <p>I'm trying to login to AliExpress through PhantomJS, but my script doesn't work and I can't figure out why.</p>
  <p>I'm using PhantomJS Version 2.0.0.</p>
  <p>The login form is inside an iframe, maybe that's the problem.</p>
  <p>This is the code:</p>
  <pre><code>var page = new WebPage(), step = 0, loadInProgress = false, timeOut = false;
  var url = 'https://login.aliexpress.com/buyer.htm?spm=2114.11040108.1000002.7.8yVuzJ&amp;return=http%3A%2F%2Fcl.aliexpress.com%2F';
  </code></pre>
  <p>Function to fill and submit the form inside the i-frame.</p>
  <pre><code>var sendForm = function(){
      var iframeRef = function( frameRef ) {
          return frameRef.contentWindow
              ? frameRef.contentWindow.document
              : frameRef.contentDocument;
      };
  
      var iframe = iframeRef(document.getElementById('alibaba-login-box'));
      var arr = iframe.getElementById('login-form');
      arr.elements[&quot;fm-login-id&quot;].value=&quot;my-email&quot;;
      arr.elements[&quot;fm-login-password&quot;].value=&quot;my-password&quot;;
      iframe.getElementById('login-form').submit();
      console.log(&quot;Form submitted.&quot;);
  };
  </code></pre>
  <p>These are the steps that my program follows:</p>
  <pre><code>var onFinishedSteps = [
      //Opens the web to log-in.
      function(){
          page.open(url);
      },
      //Fills the form and submits it.
      function(){
          page.render('0before fill.png');
          page.evaluate(sendForm);
          page.render('1just after submit.png');
      },
      //Renders the web ~10 seconds after submitting.
      function(){
          console.log(&quot;timeout setted&quot;);
          timeOut = true;
          window.setTimeout(
              function () {
                  console.log(&quot;timeout function&quot;);
                  page.render('2timeout.png');
                  timeOut = false;
              },
              10000 // wait 5,000ms (5s)
          );
      }
  ];
  </code></pre>
  <p>First the web page is loaded, then the form is filled and submitted (and rendered).
  This two steps works fine. The rendered images shows the filled inputs (email and password) and the i-frame content properly.</p>
  <p>The third step should give the program enough time to process the form and login, but the rendered image still shows the form, this time with the password input empty and no message (like 'incorrect password' or something like that).</p>
  <p>This is the rest of the program:</p>
  <pre><code>page.onNavigationRequested = function(url, type, willNavigate, main) {
      console.log('Trying to navigate to: ' + url);
      console.log('Caused by: ' + type);
      console.log('Will actually navigate: ' + willNavigate);
      console.log('Sent from the page\'s main frame: ' + main);
  };
  
  page.onLoadStarted = function() {
      loadInProgress = true;
  };
  
  page.onLoadFinished = function(status) {
      loadInProgress = false;
  };
  
  interval = setInterval(function() {
      if (!loadInProgress &amp;&amp; typeof onFinishedSteps[step] == &quot;function&quot;) {
          console.log(&quot;----------------------- Step &quot; + (step + 1));
          onFinishedSteps[step]();
          step++;
      }
      if (!loadInProgress &amp;&amp;  !timeOut &amp;&amp; typeof onFinishedSteps[step] != &quot;function&quot;) {
          console.log(&quot;test complete!&quot;);
          phantom.exit();
      }
  }, 50);
  </code></pre>
  <p>Here is a link with the complete file if you want to test it.
  Github: <a href="https://github.com/xAlstrat/PhantomJsFunctions/blob/master/aliexlogin.js" rel="nofollow noreferrer">https://github.com/xAlstrat/PhantomJsFunctions/blob/master/aliexlogin.js</a></p>