1

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:\Users\Memmo\Pictures\Camera 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.

4
  • Does this help? stackoverflow.com/questions/48294349/… Commented Aug 11, 2022 at 10:24
  • I am confused: what are you trying to do? Are you trying to login to that website, then upload images? Or are you trying to click the 'load more' button? Or are you trying to scroll the page, to load more images? Or are you trying to download images into a folder on your machine? Can you please explain? Commented Aug 11, 2022 at 19:46
  • @platipus_on_fire I am already currently logged in. Automatically I have to insert images: either in the Vinted panel or through the system browser that opens by clicking on the Upload photos button Commented Aug 12, 2022 at 13:46
  • Maybe.. someone with an account on Vinted, or someone living in Italy would give this a hard look and some testing; otherwise, if you really want an answer, you could create a mock profile for testing, and provide us with access. Commented Aug 12, 2022 at 20:20

4 Answers 4

1
+150

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

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

Comments

1

You cannot access the upload window opened by the browser since selenium does not have access outside of the browser page.

You can archive this by installing some other python package that will allow you to have access to the opened window (given you are starting the browser in local machine) or much simpler way would be to get the file input field (in most cases hidden) and assign the image path to it.

Here is a small example: (have not tried it in vinted, I don't have an account there and I'm too lazy to verify my phone number :))

# [...]

# get the file input field
# (on most pages css: input[type="file"] or xpath: //input[@type="file"] 
# would be enough, but check if there are more than one file input fields
# in which case you'd have to use index like [0],[1],[n]

# logic on waiting element
# [...]

fileInput = driver.find_element(mode, 'input[type="file"]')
fileInput.send_keys(get_images(directory_path))

# and finally click on the form submit button.
# [...]

4 Comments

unfortunately there is no input field and sendkeys is deprecated in the latest versions of python...
@Memmo do you have a link to docs stating send_keys is deprecated?
@Memmo: Tgere is an input field is there under div with id= photos. Please refer my answer for xpath
I wouldn't mind a small up vote. :)
-1

If loosing focus on a desktop window is causing problem, than it can be easily fixed as following:

  • Create a .VBS file with following code at some location:

    Set oShell = CreateObject("Wscript.shell")

    oShell.AppActivate("<Enter the Window Title Here>")

  • Before sending any keys simple invoke the .vbs file to set the focus

P.S.

  • This solution only works on windows
  • Partial Windows title also work

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
-1

I was unable to login to the website but I was able to look for some libraries for getting info ("https://github.com/aime-risson/vinted-api-wrapper") and ("https://github.com/hipsuc/Vinted-API/blob/main/VintedApi.py")

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.