0

How do I upload a file using Selenium tool in automation testing? I tried with the following code:

selenium.attachFile(//*[@id='file-uploader']/div/div[1]",
    "C:\\Users\\Public\\Pictures\\Sample Pictures\Desert.jpg"); 

This is the error I am getting:

Malformed URL C:\\Users\\Public\\Pictures\\Sample Pictures\\Desert.png.
Perception
  • 79,279
  • 19
  • 185
  • 195
anu1989
  • 39
  • 2
  • 7

1 Answers1

0

It has to be in this format:

file://C:\Users\Public\Pictures\Sample%20Pictures\Desert.jpg

We're dealing with the Windows world, so the slashes are backwards.

Try this:

selenium.attachFile(//*[@id='file-uploader']/div/div[1]",
"file://C:\\Users\\Public\\Pictures\\Sample Pictures\\Desert.jpg"); 
Manual5355
  • 981
  • 10
  • 27
  • I don't know if you have to escape the space or not. Try it both ways and tell me which way works. I'll update my answer. – Manual5355 Jun 06 '12 at 18:05