0

This element

This is the element I don't know how to "bite". I want to upload, for example, photo "image.jpg" from the py folder. Unfortunately any features I found doesn't work. In this screenshot, I can drag and drop photo OR click button and add manually.

This is the code after logging in to IG.

 upload1 = driver.find_element_by_xpath("/html/body/div[1]/section/nav/div[2]/div/div/div[3]/div/div[3]/div/button").click()
time.sleep(4)
## space for upload code

##
time.sleep(4)
upload3 = driver.find_element_by_xpath("/html/body/div[6]/div[2]/div/div/div/div[1]/div/div/div[2]/div/button").click()
time.sleep(1)
upload4 = driver.find_element_by_xpath("/html/body/div[6]/div[2]/div/div/div/div[1]/div/div/div[2]/div/button").click()
time.sleep(1)
with open('mart2.txt') as f:
    lines = f.readlines()
    i = random.randrange(len(lines))
opis = driver.find_element_by_xpath("/html/body/div[6]/div[2]/div/div/div/div[2]/div[2]/div/div/div/div[2]/div[1]/textarea")
time.sleep(1)
opis.send_keys("Hello this is test" + (lines[i]))
time.sleep(1)
confirm = driver

Do you have any idea how to automatically upload photo here? Thanks in advance!

mattwass6
  • 1
  • 1
  • I never did somethibg like that, but my 2 cents on this is to try writing the image path in the upload input field (if it exists). – Mihnea-Octavian Manolache Jan 07 '22 at 11:53
  • thanks for reply. unfortunately, there are no field, as you can see on screenshot :( – mattwass6 Jan 07 '22 at 11:59
  • Check if you have `type=file` attribute in the DOM of upload. If yes, you can just pass in the path. If not, try using some libraries like `pyautogui` This might be of help to you [pyautogui SO](https://stackoverflow.com/questions/8665072/how-to-upload-file-picture-with-selenium-python) – Anand Gautam Jan 07 '22 at 13:40

0 Answers0