Skip to content
Advertisement

Automatically upload images on vinted

I’ve been stuck on a task for a few days. I can’t load images automatically on the vinted image browser. I tried running the following code:

from os import listdir
from os.path import isfile, join
from time import sleep

from pyautogui import press, write
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager

def get_images(directory_path) -> str:
    images: str = ""
    f: str
    image_name: str
    for filename in listdir(directory_path):
        f = join(directory_path, filename)
        if isfile(f):
            image_name = f.replace(f"{directory_path}\", "")
            images += f'"{image_name}" '

    return directory_path + "\" + images

option: Options = Options()
option.add_experimental_option("debuggerAddress", "localhost:8989")

driver: Chrome = Chrome(service=Service(ChromeDriverManager().install()),
                        options=option)

mode: str = By.CSS_SELECTOR

driver.maximize_window()
driver.get("https://www.vinted.it/items/new")

# * images
sleep(1)
driver.find_element(mode, "#photos > div.Cell_cell__3V4ao.Cell_wide__1ukxw > div > div > div > div.media-select__input > div > button").click()
sleep(1)
directory_path: str = r"C:UsersMemmoPicturesCamera Roll"
write(get_images(directory_path))
press('enter')

The problem is that the paths of the recovered images end up on the terminal where the script is run, while they should be set in the upload window. It almost seems that the focus is lost.
I could also set the html of the image on the upload section but it seems a more complicated, expensive and risky way than the one already undertaken.

If someone has already faced “more custom” image browsers compared to the classic ones, I would be curious to know how solved this problem.

Thanks in advance.

Advertisement

Answer

To upload the file you need to use xpath as "//div[@id='photos']/input"

here is the full code

driver.find_element(By.XPATH, "//div[@id='photos']/input").send_keys("<your image file path>")

Here is the screenshot that shows its working for me

enter image description here

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement