title: Using Selenium to make Instagram Bot
body: <p>I'm trying to make a bot in Python that directly messages a user of my choice. I was able to code everything up and until selecting 'Message' on the persons profile.</p>
  
  <p>Part of the code that works:</p>
  
  <pre><code>from selenium import webdriver
  from selenium.webdriver.common.keys import Keys
  from time import sleep, strftime
  from random import randint
  
  
  chromedriver_path = 'C:/Users/JACOB/Downloads/chromedriver_win32 (1)/chromedriver.exe' 
  webdriver = webdriver.Chrome(executable_path=chromedriver_path)
  sleep(2)
  webdriver.get('https://www.instagram.com/accounts/login/?source=auth_switcher')
  sleep(3)
  
  username = webdriver.find_element_by_name('username')
  username.send_keys('MYUSERNAME')
  password = webdriver.find_element_by_name('password')
  password.send_keys('MYPASSWORD')
  
  button_login = webdriver.find_element_by_css_selector('#react-root &gt; section &gt; main &gt; div &gt; article &gt; div &gt; div &gt; div &gt; form &gt; div &gt; button.sqdOP.L3NKy.y3zKF')
  button_login.click()
  
  sleep(4)
  
  notnow = webdriver.find_element_by_css_selector('#react-root &gt; section &gt; main &gt; div &gt; div &gt; div &gt; div &gt; button.sqdOP.yWX7d.y3zKF')
  notnow.click()
  
  sleep (4)
  
  postnotifications = webdriver.find_element_by_xpath('/html/body/div[4]/div/div/div/div[3]/button[2]')
  postnotifications.click()
  
  sleep(3)
  
  mydms = webdriver.find_element_by_xpath('//*[@id="react-root"]/section/nav/div[2]/div/div/div[3]/div/div[2]/a/svg')
  mydms.click()
  
  search = webdriver.find_element_by_xpath('//*[@id="react-root"]/section/nav/div[2]/div/div/div[2]/input')
  search.send_keys('INSTAGRAM_USERNAME')
  
  sleep(2)
  
  foundit = webdriver.find_element_by_xpath('//*[@id="react-root"]/section/nav/div[2]/div/div/div[2]/div[2]/div[2]/div/a/div/div[2]/div/span')
  foundit.click()
  
  sleep(3)
  </code></pre>
  
  <p>This code takes me all the way to a users page. However when I attempt to 'click' on the Message button, the xpath can't be found. Here is the code:</p>
  
  <pre><code>message = webdriver.find_element_by_xpath('//*[@id="react-root"]/section/main/div/header/section/div[2]/div[1]/div/button')
  message.click()
  </code></pre>
  
  <p>I found the xpath by right clicking on the Message button > Inspect > Highlighting the HTML code on the right hand side > Copy > Copy XPath.</p>
  
  <p>I've also tried the full xpath and it can't seem to find it either. </p>
  
  <p>Here is a screenshot of the button I'm referring too:</p>
  
  <p><a href="https://i.stack.imgur.com/jm99g.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jm99g.png" alt="enter image description here"></a></p>