title: Selenium with Ruby : Handling JS Prompt with 2 fields
body: <p>I want Selenium to connect to my Staging site, which is hosted on WPEngine. Therefore each time I connect, it asks me for a user name and password, in a Javascript prompt.</p>
  
  <p>I can easily send text to the first (user name) field in the prompt :</p>
  
  <pre><code>def connectToStaging()
      alert = @browser.switch_to.alert
      if /username and password/.match(alert.text)
          alert.send_keys("username")
      end
  end
  </code></pre>
  
  <p>But then I don't know how to switch to the password field to do the same.</p>
  
  <p>I've tried sending a tab character right after sending the string "username" :</p>
  
  <pre><code>alert.send_keys(:tab)
  </code></pre>
  
  <p>But it returns an error : <strong>NoMethodError: undefined method `split' for :tab:Symbol</strong></p>
  
  <p>Otherwise I don't know if there's a way to target the field using <strong>find_element</strong> ? Or is there a function to switch to the next field in whatever window or form the pointer is in at the moment ?</p>
  
  <p>Thanks so much !</p>