Saturday, May 30, 2009

Uploading Files using Selenium RC in C#

After googling all around to overcome the Selenium incapability of handling File Upload control finally I could write a simple function in C# which will do my job. In the function given below _selObj is the object of DefaultSelenium class.

public bool TypeIntoFileUpload(string controlId, string filePath)
        string newFilePath = filePath.Replace('\\', '/');
        string jscript="";
        jscript += "if(selenium.browserbot.getCurrentWindow().clipboardData){window.clipboardData.setData('Text','" + newFilePath + "');}";
        byte VK_CONTROL = 0x11;
        byte VK_V = 0x56;

        return true;
    catch (Exception exc)
        return false;


  1. It does not work. I tried it

  2. I tried too, it does not work.