2

This is my code.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.alert import Alert
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Firefox()
driver.get('url')

wait(driver, 30).until(EC.alert_is_present())

alert=driver.switch_to_alert()


alert.send_keys('user')
alert.send_keys(Keys.TAB)
alert.send_keys('pass')
alert.accept()

The popup window is launched, but nothing changes after it. Any ideas?

WillWill
  • 35
  • 1
  • 6
  • So the popup window appears without you having to click on anything? – John Gordon Mar 03 '16 at 23:11
  • I thought alert windows were special windows that only take OK or Cancel as input. If you can enter a username and password, is it really an _alert_ window, or just a generic pop-up window? – John Gordon Mar 03 '16 at 23:19
  • it is a pop up window. it ask for username and password. – WillWill Mar 04 '16 at 00:01
  • OK, so it's not really an _alert_ window. So, I don't think `switch_to_alert` will work. – John Gordon Mar 04 '16 at 02:30
  • Any suggestions? What should I do? – WillWill Mar 04 '16 at 03:53
  • You can use one of the `find_element_by_X` functions to locate the input fields and then send input to them. If they have IDs, then `find_element_by_id` is the best function to use. Otherwise you could use `find_element_by_name`, etc. – John Gordon Mar 04 '16 at 04:52
  • Does it really web pop up or `Windows` native window? – Andersson Mar 04 '16 at 05:34
  • username = selenium.find_element_by_id("User Name") password = selenium.find_element_by_id("Password") username.send_keys("YourUsername") password.send_keys("Pa55worD") selenium.find_element_by_name("Log In").click() Still not working – WillWill Mar 04 '16 at 05:35
  • When you click on the login button, then it leads you to a window with the popup and ask for user name and password @Andersson – WillWill Mar 04 '16 at 05:40
  • @WillWill, can you click right button to see `http` source code on user/password input field? – Andersson Mar 04 '16 at 05:43
  • @Andersson it doesn't allow you to see it. the website is portal.adp.com – WillWill Mar 04 '16 at 05:47
  • @WillWill, if so, you will not be able to complete authentication with `Selenium` as it allow to operate only with web elements – Andersson Mar 04 '16 at 05:50
  • @Andersson is there a way that I can do it? – WillWill Mar 04 '16 at 05:53
  • Websites can't prevent you from looking at the page source. On Firefox, if you right-click anywhere on the page, you will get a menu with "View Page Source" as an option. I imagine other browsers work in similar ways. Once you see the source, you can find the `id` value of the input fields. ("Log In" probably is not the id value.) – John Gordon Mar 07 '16 at 19:16

1 Answers1

3

You could try to authenticate with following url form:

driver.get('https://username:password@portal.adp.com')

Change username and password to your real credentials.

Ulf Gjerdingen
  • 1,414
  • 3
  • 16
  • 20
Andersson
  • 51,635
  • 17
  • 77
  • 129
  • This actually works..I just need to find the correct URL. – WillWill Mar 08 '16 at 03:40
  • @UlfGjerdingen, "won't work anymore" or "it doesn't work in your case"? This was the solution for this particular case- I didn't claim that this should **"work in chrome"**. Your web-app might use different authentication scheme, so this approach is not acceptable **in your particular** case. There is no reason for downvote, so please cancel it – Andersson Feb 03 '17 at 09:21
  • true. sorry. i need to edit it first, then i'll remove my downvote. – Ulf Gjerdingen Feb 03 '17 at 09:23
  • how about if the password contains the @ sign – Scorpisces Mar 15 '21 at 02:22