0

I am trying to upload a jpg file on website using selenium and python.

I happened to find a way to do so and succeeded on a practice website. (http://demo.guru99.com/test/upload/)

but when I tried my real target website, the method did not work.

This is the elements of the website regarding file uploading.

<span class="reg_btn_full"><input type="file" name="btnSelectFile" class="reg_file" cmd="reg"></span>
<input type="file" name="btnSelectFile" class="reg_file" cmd="reg">

I couldn't find ID in the elements so I used X path.

This is my code.

driver.find_element_by_xpath("the x path").send_keys("D:/1.jpg")

and the error code was like this.

Exception has occurred: InvalidArgumentException
Message: File not found: D:/1.jpg

Do you think it has something to do with form element?

If you think so, please tell me what to do.

ppooppoo
  • 13
  • 4

2 Answers2

1

https://stackoverflow.com/a/51446063/1387701 Basically it's trying to load that file path, not type it in. You'll need to download the file locally it looks like.

DMart
  • 2,401
  • 1
  • 14
  • 19
  • Sorry sir, but I don't get it. I designated local path as "D:/1.jpg" and the file is actually there.(As I said, I succeeded upload the file on other website.) Why do you think I need to locally download the file? – ppooppoo Oct 26 '20 at 23:21
  • The error is file not found. It apparently isn't located at that path, or python doesn't have permissions ot load it. – DMart Oct 27 '20 at 15:49
  • When you say it runs on other webstie, what have you changed between execution? – DMart Oct 27 '20 at 15:51
0

I finally solve the problem.

The answer was very simple.

I focused that the error message was "file not found"

I tried many ways and when I changed "/" to "//" it worked.

I simply changed "D:/1.jpg" to "D://1.jpg" it magically worked.

I still don't know why and other websites work fine with "D:/1.jpg"

but anyways, my problem has been solved.

ppooppoo
  • 13
  • 4