0

I have a password protected proxy whose username and password constantly change so I need to always enter them in the firefox prompt that shows when you start the browser. I can't find anyway to switch from the username input to the password input. I've been using this code to handle the alert:

try:
    WebDriverWait(driver, 3).until(EC.alert_is_present(),
                                   'Timed out waiting for PA creation ' +
                                   'confirmation popup to appear.')

    alert_input = Alert(driver)
    alert_input.send_keys('username')
    alert_input.send_keys(Keys.TAB)
    alert_input.send_keys('password')
    alert_input.accept()
    print("alert accepted")
except TimeoutException:
    print("no alert")

However, this doesn't work because after entering the username into the username field, it replaces it with  and doesn't move to the password field. So what I'm assuming is that it literally enters the tab into the username field instead of tabbing to the password field. Is there a way to switch fields without the tab key or somehow do it with the tab key?

Thanks

chow
  • 19
  • 1

1 Answers1

1

rather than sending tab key to the browser you can get username and password element by id name or xpath and send input. Here is the example:

username = driver.find_element_by_name("name of the username field")
username.send_keys("username")
password = driver.find_element_by_name("name of the password field")
password.send_keys("password")
Sunit
  • 382
  • 1
  • 12
  • The problem is I don't know the name of the element in the in browser firefox prompt. – chow Jul 01 '15 at 06:26
  • ok so you are dealing with alert javascript popup. have a look on this link it might help http://selenium-python.readthedocs.org/en/latest/api.html#module-selenium.webdriver.common.alert – Sunit Jul 01 '15 at 07:29