使用python打开带有selenium的sharepoint网站时如何填写弹出窗口中的字段? [英] How to fill fields in a popup when opening a sharepoint website with selenium using python?

查看:59
本文介绍了使用python打开带有selenium的sharepoint网站时如何填写弹出窗口中的字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过使用 selenium 和 python,我正在尝试为 sharepoint 页面开发自动化的 web/GUI 测试.我遇到的问题是身份验证,它以 window/popup/alert/I_dont_know 的形式呈现如下

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

在代码中我尝试了以下组合(基于 这个建议):

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()

我尝试了 windows 和 alert,但是在 alert 的情况下什么也没有发生,在 window 的情况下我得到一个错误:

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'

可能在driver.window_handles中没有window..

如何解决此问题以便将用户名和密码发送到该框?它应该用于 firefox、chrome 和 IE,因为我打算使用 selenium 对这些共享点页面进行功能测试.因此,我需要以不同的用户身份登录才能测试权限...

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...

补充:

  • 代码执行似乎挂在这一行:alert = driver.switch_to_alert()

推荐答案

你可以试试这个:

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}")

这篇关于使用python打开带有selenium的sharepoint网站时如何填写弹出窗口中的字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆