您的位置:首页 > 其它

Selenium RC upload local file

2014-01-27 17:55 381 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: