使用C#从OpenFileDialog中选择一个文件 [英] Choose a File from OpenFileDialog with C#

查看:249
本文介绍了使用C#从OpenFileDialog中选择一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小问题-我不知道如何选择文件并在Mozilla OpenFileDialog中打开它.

I have a little problem - I don't know how to Select a File and Open it in the Mozilla OpenFileDialog.

首先,我用Selenium按下浏览"来打开对话框,然后我想输入一个文件名(我通过环境变量知道确切的位置)

First, I open the Dialog by pressing "Browse" with Selenium and then I want to put in a File-Name (I know the exact location via Environment variable)

在我的情况下:Environment.GetEnvironmentVariable("Testplatz_Config_Location")+"\ TestConfig.fpc"

In my case: Environment.GetEnvironmentVariable("Testplatz_Config_Location") + "\TestConfig.fpc"

所以我的问题是,有谁知道如何使用C#处理已经打开的OpenFileDialog-还是可以用Selenium处理呢?

So my Question, does anyone know how to handle an already open OpenFileDialog using C# - Or is it perhaps possible to handle this with Selenium?

推荐答案

您可以在文件上载元素上使用sendKeys()来使用硒按路径上载文件.我建议使用它代替AutoIT或Robot.

You can use sendKeys() on the file upload element to upload a file using selenium by path. I would suggest using this instead of AutoIT or Robot.

因此,您无需单击浏览按钮,而是使用sendKeys()将路径直接发送到文件输入元素.

So instead of clicking on the browse button, you send the path directly to the file input element using sendKeys().

示例:

IWebElement element = driver.FindElement(By.Id("file_input"));
element.SendKeys(
    Environment.GetEnvironmentVariable("Testplatz_Config_Location") + "\TestConfig.fpc");

这篇关于使用C#从OpenFileDialog中选择一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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