Selenium RC use attachFile() to upload the local file.
作者: Max.Bai
时间: 2014/01
Selenium RC upload local file
1. Use attachFile()
set browser "*chrome ..." replace "*firefox..."
The upload file only can be save on C: driver(maybe system dir)
The fileLocator is URL
--for network path like "http://localhost/abc.txt"
--for local path like "File:///C:/tem/abc.txt", but need remove the c:/ string for AttchFile method.
Sample for c#:
the browser button locator is "//input[@id='inputFile']"
string sLocalFile = @"C:\uploadFolder\uploadfile.txt";
string sFileLocator = @"file:///uploadfolder/uploadfile.txt";
Selenium.AttachFile("//input[@id='inputFile']", sFileLocator);
Selenium.Click("//input[@id='OkButton']");
/// <summary>
/// Attach local file
/// </summary>
/// <param name="sFilePath">local file path, only accept C: driver</param>
/// <returns></returns>
public void UploadFile(string sFilePath)
{
Selenium.AttachFile(Page.Browse_Button.Selector, new Uri(sFilePath).ToString().ToUpper().Replace("C:/", ""));
}
Note: only support firefox, Need check in IE
2. Use autoit
This solution can be found on web.
Selenium Webdriver upload file:
http://blog.csdn.net/max229max/article/details/36664121