title: How to handle a window popup with wdio?
body: <p>I'm trying to handle a facebook auth dialog popup via webdriverio. The problem is that I can't seem to target the email/password fields for the facebook signup. </p>
  
  <p>Here's my code:</p>
  
  <pre><code>it('redirects after signup', () =&gt; {
      browser.url('/');
  
      const mainTab = browser.getCurrentTabId();
      browser.waitForExist('[data-test="facebook-login-button"]');
      browser.click('[data-test="facebook-login-button"]');
  
      // fb login form
      browser.waitForExist('#email');
      browser.setValue('#email', this.fbAccount.email);
      browser.setValue('#pass', this.fbAccount.password);
      browser.click('input[type="submit"]');
  
      // fb login authorization
      browser.waitForExist('button[type="submit"]');
      browser.click('button[type="submit"]');
  
      browser.switchTab(mainTab);
      browser.waitForExist('[data-test="intro-title"]');
  });
  </code></pre>
  
  <p>I had also attempted to wait until the tab opens by doing the following</p>
  
  <pre><code>browser.waitUntil(() =&gt; browser.getUrl().indexOf('facebook.com') &gt; -1);
  </code></pre>
  
  <p>And another attempt was to switch tabs to the facebook tab more explicitly</p>
  
  <pre><code>browser.switchTab(   
   browser.windowHandles().value[browser.windowHandles().value.length]
  );
  </code></pre>
  
  <p>All of these variants just result in <code>browser.waitForExist('#email');</code> failing (that is timing out and not finding the email input after 30s). That being said, the popup does indeed open, and it is indeed focused. Even when I manually try to focus wdio, webdriver or selenium doesn't find the element in question.</p>
  
  <p>How is this sort of thing supposed to work? What am I doing wrong? Are there recommendations for making this sort of test successful?</p>