0

I am trying to upload a file using selenium. but the problem is my upload field is not like

<input type="file".....> [where i can directly say "selenium.type("xpath ","file path") ]

but here, for uploading file we are using a Rad Uploader, and it is not recording anything in selenium IDE even though i click on uploader.

Does anybody know how to upload file with Raduploader using Selenium?

<object height="22px" type="application/x-silverlight-2" data="data:application/x-silverlight-2," 
id="ctl00_ctl00_ContentPlaceHolder1_mainTabContainer_thirdTab_ChildPlaceHolderCa‌​mpVolunteers_fileUploadVolunteersilverlight04"
class="ruObject" style="width: 100%;"> 

this is some part of the code of upload field

Thanks.

Ranadheer Reddy
  • 4,202
  • 12
  • 55
  • 77
  • When you are posting question on stack-overflow, It should be proper formatted and all important keywords should be highlighted. – shobhit Jun 14 '12 at 05:59
  • Read this http://stackoverflow.com/faq#editing and particularly the last line. – shobhit Jun 14 '12 at 06:35

1 Answers1

1

Since Rad Uploader is basically a Java Applet, you could use LiveConnect to interact with it!

There is even a tool for it and Selenium (though I'm not using it, so I can't tell whether it works well or not): http://fest.codehaus.org/Selenium

If it doesn't work, then you'll probably need to use a different automation library to upload the files, because Selenium is not built to work neither with Java applet, nor outside the browser. Possible solutions include drag'n'dropping or (Ctrl+C + Ctrl+Ving) the files from outside the window to your Uploader, or clicking blindly on the Browse button...


Edit

I was obviously looking at the wrong product, because OP's code shows it's actually a Silverlight element, not a Java applet.

But - knowing that there's a tool for this for Java applets, I digged and found these:

There is a tool for using Selenium RC with Silverlight! No idea how well it actually works, but you could give it a try. Yes, I know it's only Selenium RC, but you could try it with WebDriverBackedSelenium...

Scott Hanselman's blog (very readable!) - "abusing" that Silverlight can run Scriptable methods. It is written for Selenium IDE, but the same will work for WebDriver, too.

A testing framework for Silverlight. By Microsoft. Selenium is for webpages, try this for some Silverlight magic.


EDIT 2:

There's always the option I mentioned earlier. Since the upload thing is no input, but a Silverlight object and there's no API for WebDriver that would allow you to work with browser dialogs (or Silverlight objects), you can try this:

After you click the Silverlight element, there'll be a window popping up that you'll have no control over. In the browsers and operating systems I know, you can pretty much assume that after the window has been opened, the cursor is in the File name input. Please, make sure this assumption is true in your case, too.

If not, you could try to jump to it by pressing Alt + N, at least on Windows...

(Java code follows! I really don't know C#. It works in Java, though. C#'s class that is similar to Java's Robot is SendKeys)

If yes, you can "blindly" type the path into it using the Robot class. In your case, that would be something in the way of:

driver.findElement(By.id("SWFUpload_0")).click();
Robot r = new Robot();
r.keyPress(KeyEvent.VK_C);        // C
r.keyRelease(KeyEvent.VK_C);
r.keyPress(KeyEvent.VK_COLON);    // : (colon)
r.keyRelease(KeyEvent.VK_COLON);
r.keyPress(KeyEvent.VK_SLASH);    // / (slash)
r.keyRelease(KeyEvent.VK_SLASH);
// etc. for the whole file path

r.keyPress(KeyEvent.VK_ENTER);    // confirm by pressing Enter in the end
r.keyRelease(KeyEvent.VK_ENTER);

It sucks, but it should work. Note that you might need these: How can I make Robot type a `:`? and Convert String to KeyEvents

Community
  • 1
  • 1
Petr Janeček
  • 37,768
  • 12
  • 121
  • 145
  • Actually the link which you gave is based on java. But i am working with c#. – Ranadheer Reddy Jun 15 '12 at 05:18
  • i used firebug and found the **html** code of **upload field**. it is like this, `` i tried `selenium.type` command but it's not working. – Ranadheer Reddy Jun 15 '12 at 05:21
  • `` this is some part of the code of **upload field**. – Ranadheer Reddy Jun 15 '12 at 05:23
  • Okay, so it's a Silverlight object, not a Java applet (Huh, so there are more Rad Uploaders out there. I was looking at [this one](http://www.radinks.com/upload/) which is a Java applet.) The question gets edited. – Petr Janeček Jun 15 '12 at 13:09
  • i din't find any useful information. i have downloaded silverenium(silverlight+selenium) from the above link. but am unable to do anything with it. – Ranadheer Reddy Jun 19 '12 at 06:27
  • Edited with the "blind typing" solution that works e.g. for Flash upload when done in Java. You'll need to do some research on the SendKeys class, though. – Petr Janeček Jun 29 '12 at 09:51