Hello so because the instagram API ain't working anymore but i still want a instagram bot, I started my own little project. Everything is going fine until i got to a very interesting thing.
When i click on the upload picture button the file dialoge appears, that is also planed, then what i wanted to do is to simulate Keypresses, so nothing special (also did that a little earlier in my script) but for what ever reason my python script just stops when it comes to the file dialog, without a Error or anything else, the script is also still active it just doesnt want to go to next line.
from selenium import webdriver
from time import sleep
import keyboard
from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Chrome()
driver.get("https://instagram.com")
sleep(2)
#login into Account
username = driver.find_element_by_xpath("/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div/div[1]/div/label/input")
password = driver.find_element_by_xpath("/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div/div[2]/div/label/input")
loginBtn = driver.find_element_by_xpath("/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div/div[3]/button")
#put your username and password here
username.send_keys("username")
password.send_keys("pw")
loginBtn.click()
sleep(4)
#----------------------------------
safeLoginDateBTN = driver.find_element_by_xpath("/html/body/div[1]/section/main/div/div/div/div/button")
safeLoginDateBTN.click()
sleep(4)
notNowNotifications = driver.find_element_by_xpath("/html/body/div[4]/div/div/div/div[3]/button[2]")
notNowNotifications.click()
sleep(4)
#now comes the interestig part
#The problem is that there is no instgram API anymore so what are we going to do?
#exactly we are going to say instagram that we are actually a smarthphone so the browser switches to "phone mode"
keyboard.press_and_release('F12')
sleep(2)
keyboard.press_and_release('Cmd+Shift+M')
sleep(2)
driver.refresh()
#now we are in the device mode
#this is a little workaround because the sh*ti instagram api isnt working anymore
#now comes the upload part
uploadPictureBtn = driver.find_element_by_xpath("/html/body/div[1]/section/nav[2]/div/div/div[2]/div/div/div[3]")
uploadPictureBtn.click()
keyboard.press_and_release('PicsForInstagram')
keyboard.press_and_release('Enter')
The page 'sits' because selenium cannot handle upload windows, in order to do that you need to use AutoIt (if you are on windows) or Robot Framework to handle that. In the past it also worked with send_keys method on the input file.