how can I use selenium in python to send direct messages in instagram?

Viewed 5266

Hi i'm a newbie and i want to try and make an instagram bot using selenium to send birthday messages to my friends and i ran into a problem when I learned that to send dms in chrome you have to inspect the page and click on the mobile option then select a mobile device on which to view it then reload the page; all of which i don't know how to do. i have searched for an answer but have not found any.

from selenium import webdriver
from time import sleep
from secrets import pw
from secrets import username

class InstaBot:
    def __init__(self, username, pw):
        self.driver = webdriver.Chrome('D:\Movies/chromedriver.exe')
        self.username = username
        self.driver.get("https://instagram.com")
        sleep(6)
        self.driver.find_element_by_xpath('/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div[2]/div/label/input')\
            .send_keys(username)
        self.driver.find_element_by_xpath("//input[@name=\"password\"]")\
            .send_keys(pw)
        self.driver.find_element_by_xpath('//button[@type="submit"]')\
            .click()
        sleep(4)
        self.driver.find_element_by_xpath("//button[contains(text(), 'Not Now')]")\
            .click()


        #keeps window open
        while x == 1:
            sleep(10)

x = 1




InstaBot(username, pw)           
2 Answers
mobile_emulation = { "deviceName": "Nexus 5" }
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument ("lang = en_us")
    chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)
Related