Selenium FileUpload accept()没有单击按钮

时间:2018-11-15 06:32:42

标签: python-3.x selenium selenium-iedriver iedriverserver

已在IE中打开文件选择器对话框,

self.webDiver.switch_to_alert().accept()

尝试了上面的行,但没有单击打开按钮。

  

IE版本11.2580.14393.0;

     

Windows Server 2016 Standard

显示的对话框是“选择要上载的文件”,此对话框具有一个文件名文本框,其中包含一个组合框+打开按钮以及一个打开按钮,该按钮是一个SplitButtonControl,具有打开/打开只读或另存为选项。以前的版本。

1 个答案:

答案 0 :(得分:0)

当前的解决方法是使用uiautomation:

import uiautomation as automation

print(automation.GetRootControl())
uiWindow = automation.WindowControl(searchDepth = 2, Name = 'Choose File to Upload')
print(uiWindow.Name)
uiWindow.SetTopmost(True)
fileName = uiWindow.EditControl(searchDepth = 4,Name = 'File name:')
fileName.SendKeys("State of testing.MicroFocus.pdf")
openFile = uiWindow.SplitButtonControl(searchDepth = 3,Name = 'Open')
openFile.Click()

来源:https://github.com/SeleniumHQ/selenium/issues/6140#issuecomment-426215154