title: Scroll in Selenium Webdriver (Python)
body: <p>Prerequisites.<br>
  You need an account at Instagram to use this script.<br>
  Setup a test environment:<br></p>
  
  <p>Log in, open the needed list(works correctly):</p>
  
  <pre><code>from selenium import webdriver
  from selenium.webdriver.common.keys import Keys
  from time import sleep
  
  driver = webdriver.Chrome(
  # driver = webdriver.Firefox(    
  # driver = webdriver.PhantomJS(
      service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any'])
  
  driver.get("https://instagram.com/accounts/login")
  username = driver.find_element_by_name("username")
  password = driver.find_element_by_name("password")
  
  username1 = 'instagram' # change it!
  password1 = 'instagrampassword1' # change it!
  
  username.send_keys(username1)
  password.send_keys(password1)
  
  submit_button = driver.find_element_by_css_selector(
      '#react-root &gt; div &gt; article &gt; div &gt; div:nth-child(1) &gt; div &gt; form &gt; span &gt; button')
  submit_button.click()
  
  sleep(2)
  
  link = 'https://www.instagram.com/youtube/'
  driver.get(link)
  
  driver.implicitly_wait(2)
  driver.find_elements_by_class_name("_218yx")[2].click()
  </code></pre>
  
  <p>Wrong scroll. 
  How to fix this block?</p>
  
  <p>How to focus and scroll correctly on this page?</p>
  
  <p>My attempts:</p>
  
  <pre><code>driver.find_element_by_class_name("_cx1ua").send_keys(Keys.NULL) # focus
        #The element has been deleted entirely or
        #The element is no longer attached to the DOM.
  
  driver.find_element_by_class_name("_q44m8").send_keys(Keys.NULL)
  # cannot focus element
  
  driver.find_element_by_class_name("_qjr85").send_keys(Keys.NULL) 
  # cannot focus element
  
  
  for i in range(5):
      driver.find_element_by_class_name("_cx1ua").send_keys(Keys.END)
  </code></pre>
  
  <p>=============================================================<br>
  to @Moshisho :</p>
  
  <p>We need to focus on some element to activate it.<br>
  The question is what the element we need to choose to focus and how?<br> 
  This is not a "body":<br>
  something like that, but not this:</p>
  
  <pre><code>background = driver.find_element_by_css_selector("body")
  # background = driver.find_element_by_css_selector("div._2uju6")
  
  for i in range(5):
      background.send_keys(Keys.SPACE)
      time.sleep(1)
  </code></pre>
  
  <p>Without it this command do not work.</p>
  
  <hr>
  
  <p>to @Naveen :</p>
  
  <pre><code>print(driver.find_element_by_css_selector("div._a1rcs").location_once_scrolled_into_view) # {'x': 0, 'y': 0}
  print(driver.find_element_by_class_name("_cx1ua").location_once_scrolled_into_view) # {'x': 376, 'y': 229}
  print(driver.find_element_by_class_name("_q44m8").location_once_scrolled_into_view) # {'x': 376, 'y': 180}
  print(driver.find_element_by_class_name("_qjr85").location_once_scrolled_into_view) # {'x': 376, 'y': 180}
  </code></pre>
  
  <p>And what's next?</p>
  
  <pre><code>driver.execute_script("window.scrollTo(0, 3000);") # do not working
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/nHLDz.png" rel="noreferrer"><img src="https://i.stack.imgur.com/nHLDz.png" alt="https://www.instagram.com/youtube/following/"></a></p>