Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Mozilla中使用Python处理弹出窗口_Python_Windows_Selenium - Fatal编程技术网

在Mozilla中使用Python处理弹出窗口

在Mozilla中使用Python处理弹出窗口,python,windows,selenium,Python,Windows,Selenium,我正在为我弟弟创建一个脚本,它可以自动登录他的大学帐户,下载他的日历文件,然后上传到谷歌日历,因为他就是这么用的。当Google calendar提示我选择要导入的.ics文件时,我一直在点击“浏览”,但当浏览器窗口出现选择文件时(我相信是windows公共对话框),python代码会有点“暂停”,因为它会停止运行,直到关闭该窗口。我的意思是: browse = driver.find_element_by_css_selector('.gc-dialoginput') browse.clic

我正在为我弟弟创建一个脚本,它可以自动登录他的大学帐户,下载他的日历文件,然后上传到谷歌日历,因为他就是这么用的。当Google calendar提示我选择要导入的.ics文件时,我一直在点击“浏览”,但当浏览器窗口出现选择文件时(我相信是windows公共对话框),python代码会有点“暂停”,因为它会停止运行,直到关闭该窗口。我的意思是:

browse = driver.find_element_by_css_selector('.gc-dialoginput') 
browse.click() #Using Selenium here, this is the click that opens up that pop-up 'File Upload' Window

"""The showing of notepad here is just to see when this code would run. 
I have it minimized to see if ShowWindow works, and it does after the pop-up is closed"""

hwnd = win32gui.FindWindowEx(0, 0, 0, "Untitled - Notepad") 

win32gui.ShowWindow(hwnd, win32con.SW_SHOWNORMAL)

print "test"


手动关闭文件上传窗口后,ShowWindow功能和打印“测试”行都可以正常工作。我的目标是使用win32api.SendMessage将文件名发送到窗口中的输入,但在打开时没有任何功能:(我这里只有一小部分代码,但除此之外,其余代码都可以正常工作。如果需要任何帮助,我们将不胜感激。如果需要更多信息/完整代码,请告诉我!

我建议使用Selenium而不是PyWin32:


您可以将Selenium安装为Firefox的插件,然后在Firefox中录制任何您想用它执行的操作。然后您可以将录制内容导出为Python并根据需要进行编辑。

这个问题可能更适合堆栈溢出,因为代码审阅用于审阅已经运行的代码。Webdriver无法处理文件上载窗口,因为但是,它不是DOM的一部分。相反,请在单击“上载”按钮之前将完整文件路径发送到输入元素。