Reputation: 13
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.
Upvotes: 0
Views: 236
Reputation: 13
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.
Upvotes: 0
Reputation: 2461
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.
Upvotes: 1