LikeLinux
LikeLinux

Reputation: 46

Selenium: trying to upload two files but three or more files have been uploaded

I tried to add photo to Facebook marketplace in here with selenium python like this: driver.find_element(By.XPATH, '//input[@type="file"]').send_keys('C:/image.jpg') when I try to send one photo, one photo have been sent, the problem is when I try to send two or more photo like this:

driver.get('https://www.facebook.com/marketplace/create/item')
for ko in range(0, 2):
    driver.find_element(By.XPATH, '//input[@type="file"]').send_keys('C:/img_from_url.jpg')

three photos have been sent, I don't know where is the problem, so i want where I send two photo, only two photo have been sent, this is my simple code, please help me, any answer will be appreciated

Upvotes: 1

Views: 599

Answers (1)

Prophet
Prophet

Reputation: 33351

This seems to be a bug.
When uploading a file with a send_keys() method in a loop the file is being uploaded twice.
I.e. if you performing send keys 2 times the file file be uploaded 4 time, for 3 iterations 6 files will be uploaded etc.
Currently I see no solution for this issue. F.e. adding a delay inside the loop doesn't resolve it.
I see similar question was already asked but no solution was given there too.

Upvotes: 1

Related Questions