简体   繁体   English

从Selenium WebDriver读取Windows File Open对话框中的文件名

[英]Reading file name in Windows File Open Dialog box from Selenium WebDriver

I am using Selenium WebDriver + C# to handle a File upload process. 我正在使用Selenium WebDriver + C#来处理文件上传过程。 When clicked on a button, the standard Windows File Open dialog box appears. 单击按钮时,将显示标准的Windows File Open对话框。

I use SendKeys to specify the names of the files as 我使用SendKeys将文件名指定为

SendKeys.SendWait(filePath);
SendKeys.SendWait(@"{Enter}");

Sometime the file name is not filled in correctly in File Open Dialog box. 有时,文件名未在“文件打开”对话框中正确填写。 In that case I would like to read the value entered in the file name. 在这种情况下,我想读取文件名中输入的值。 How can I do it in C#? 如何在C#中做到这一点? Is there a GetKeys methods like SendKeys 是否有GetKeys方法,例如SendKeys

There is no textbox to enter filepath. 没有文本框可输入文件路径。 The user clicks "Upload files" button. 用户单击“上传文件”按钮。 And as soon as this button is clicked, the standard Windows file open dialog appears 单击此按钮后,将出现标准Windows文件打开对话框。

This may depend on the browsers that you use, but usually if you SendKeys(filepath) it should work. 这可能取决于您使用的浏览器,但是通常如果您使用SendKeys(filepath),它应该可以工作。 What the windows open dialog does is, it simply provides you a more user friendly way to enter filepath. Windows打开对话框的作用是,它只是为您提供了一种更加用户友好的输入文件路径的方式。 Not that most likely after that it'll display the filepath in the UI element. 之后,它不太可能在UI元素中显示文件路径。 So instead of SendWait, you can simply try SendKeys with a locator your element. 因此,除了SendWait之外,您还可以尝试使用带有元素定位器的SendKeys。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM