0

On Instagram, I'm using Python and Selenium to post a picture.

However, i'm a little bit lost when this new window is open : how do I'm supposed to go to the path of the file I want to post and continue ? With Selenium ? With an other Library ?

enter image description here

I read some responses, but can't find a good one about this (seeming simple) point. I can't use the input/"sendkey" option

Alex Dana
  • 1,076
  • 3
  • 14
  • 30

1 Answers1

0

Get the local path of your photo. Then upload it like you would send a key to the upload element.

dv.find_element_by_xpath("XPATH").send_keys(path of photo)

Example of use in action: Getting the local path of the photo

with os.scandir("./photos") as entries:
    os.chdir("./photos")
    photos = []
    for entry in entries:
        if entry.is_file():
            print(entry)
            photos.append(entry.name)

Upload it

# click on element where you have to upload
dv.find_element_by_xpath("/html/body/div[1]/div/div[1]/header/div/div[1]/div[2]/form/div[1]/span/span/span[2]").click()
# input file location from local system
dv.find_element_by_xpath("/html/body/div[5]/div/div/div[1]/div/form[1]/input").send_keys(photo)
Mark
  • 214
  • 2
  • 13