我在我的应用程序中使用了C# Selenium,我点击文件输入并显示(打开窗口)文件对话框。我需要传递filepath,然后按enter (返回)键。
Requirement:即使当前用户被签出,桌面也被锁定,RDP会话也关闭。
有没有可能在不打开javascript对话框的情况下提交文件?
谢谢
使用Selenium的示例
var button = web.FindElementByXPath("//span[@class='upload']");
button.Click();不工作
button.SendKeys("path"); //not input element
Windows.Forms.SendKeys.SendWait("..."); //not working for closed user session
InputSimulator.SimulateTextEntry("path"); //access denied because of Windows UIPI发布于 2018-10-12 22:38:16
在上面解释的情况下,没有文件类型的HTML输入(参见注释)。单击其他HTML元素后弹出打开文件对话框。将任何字符串传递给该元素都没有成功。
我在c#应用程序中使用的最好也可能是最简单的解决方案是使用AutoIT。
Install-Package AutoItX.Dotnet点击后调用打开对话框
AutoItX.ControlSend("Open", "", "", _sysPathToTheFile);
AutoItX.ControlSend("Open", "", "", "{ENTER}");或者,您可以调用
WinActivate(), WinWaitActive()...但是当窗口处于后台或在我的情况下,使用会话是关闭的、锁定的屏幕和相似的情况下,ControlSend()也工作得很好。
发布于 2022-05-18 14:08:02
如果在dom中有一个文件输入(<input type='file'/>),您可以这样做:
webdriver/#local-file-detector
IWebElement upload = driver.FindElement(/*select the <input> element*/);
upload.SendKeys(filepath); // as stringhttps://stackoverflow.com/questions/52749159
复制相似问题