0

With the use of selenium and python I am trying to develop automated web/GUI tests for sharepoint pages. The issue I have is the authentication, which is presented in form of a window/popup/alert/I_dont_know as follows

enter image description here

In the code I have tried the following combinations (based on this suggestion):

profile = webdriver.FirefoxProfile()
authDomains = "http://bfh.col.garaio.ch"
        profile.set_preference("network.automatic-ntlm-auth.trusted-uris", authDomains)
driver = webdriver.Firefox(firefox_profile=profile)
driver.implicitly_wait(30)
driver.get("http://bfh.col.garaio.ch/_layouts/closeconnection.aspx?loginasanotheruser=true")    

alert = driver.switch_to.alert()

#alert = driver.switch_to.window(driver.window_handles[0])
alert.send_keys('USERNAME')
alert.send_keys(Keys.TAB)
alert.send_keys('PASSWORD')
alert.accept()

I tried windows and alert, but in the alert-case nothing happens, and in the window case I get an error:

AttributeError: 'NoneType' object has no attribute 'send_keys'

probably there is no window in driver.window_handles..

How can I fix this in order to send the username and the password to that box? It should for for firefox, chrome and IE as I intend to use selenium for functional testing of those sharepoint pages. For that reason, I need to log in as different users to be able to test permissions...

Addition:

  • The code execution seems to hang in this line: alert = driver.switch_to_alert()
Community
  • 1
  • 1
Alex
  • 41,580
  • 88
  • 260
  • 469
  • Do you get past this popup if you add the username and password in the url as in `driver.get("http://:@bfh.col.garaio.ch)` ? – sowa Apr 22 '16 at 13:00
  • I tried that idea before many times - now this approach seems to work! Maybe sharepoint was very slow at this point ... I will investigate in more detail tomorrow and will get back to you... – Alex Apr 22 '16 at 14:00
  • @Alex Have your problem been resolved already? I've meet the same problem as you and can't find the correct answer. – Leo Hsieh Sep 21 '16 at 06:41

1 Answers1

-2

You can try this:

import win32com.client 
shell = win32com.client.Dispatch("WScript.Shell")
time.sleep(2)
shell.Sendkeys(user)  
time.sleep(2)
shell.Sendkeys("{TAB}")
time.sleep(2)
shell.Sendkeys(pwd) 
time.sleep(2)
shell.Sendkeys("{ENTER}")
Dino
  • 7,779
  • 12
  • 46
  • 85