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.

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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?
The error is file not found. It apparently isn't located at that path, or python doesn't have permissions ot load it.
When you say it runs on other webstie, what have you changed between execution?
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.