简体   繁体   English

从项目上传文件-Selenium WebDriver Visual Studio 2010 C#

[英]Upload File from Project - Selenium WebDriver Visual Studio 2010 C#

Do you know if I can upload a file to a webpage using Selenium WebDriver with VisualStudio10 but without writing the path of the position of the file in my computer. 您是否知道我可以使用带有Visual Studio10的Selenium WebDriver将文件上传到网页上,而无需在计算机中写入文件位置的路径。 I mean, adding this file to the project and call it from code without writing File path. 我的意思是,将此文件添加到项目中并从代码中调用它,而无需编写文件路径。 I need it for example if my tests are going to be run by people with different machines they dont have to re-write the file path with their own path, can directly upload from the project without modification. 我需要它,例如,如果我的测试将由具有不同计算机的人员来运行,他们不必用自己的路径重写文件路径,可以直接从项目上载而无需修改。 Dont know if this its clear, but I try. 不知道这是否清楚,但我尝试。 Thanks in advance! 提前致谢!

ElBandido ElBandido

I would configure the file to be Output when compiled. 我会在编译时将文件配置为Output。 You can do this by selecting the file in the Solution Explorer and opening the Properties panel. 您可以通过在解决方案资源管理器中选择文件并打开“属性”面板来执行此操作。 Set the Build Action to Embedded Resource . 将“ Build Action设置为Build Action Embedded Resource

Set the Copy to Output Directory to Copy if newer . 将“ Copy to Output DirectoryCopy if newer

You can just reference the file like: 您可以像这样引用文件:

string folder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string filePath = Path.Combine(folder, "file.txt");

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

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