title: Selenium - only sometimes sends send_keys
body: <p>I am attempting to make a script to log in to Facebook, navigate to a specific webpage through the search bar, and then click on the top result; however, the script does not always send keys in the search bar and instead fails. Any idea why this is happening?</p>
  <p>Another difficulty I am having is finding the correct path to the top search result. I have tried many different By. functions such as tag name, class, and x path yet none seem to work. Would greatly appreciate some help.</p>
  <pre><code>from ast import Return
  from selenium import webdriver
  from selenium.webdriver.common.keys import Keys
  from selenium.webdriver.common.by import By
  from selenium.webdriver.support.ui import WebDriverWait
  from selenium.webdriver.support import expected_conditions as EC
  import time
  
  driver = webdriver.Chrome(&quot;C:/Users/Carson/Desktop/chromedriver.exe&quot;)
  driver.get(&quot;https://www.facebook.com/&quot;)
  
  
  try:
      username = WebDriverWait(driver, 7).until(
      EC.presence_of_element_located((By.ID,'email')))
      
      username.send_keys(&quot;username&quot;)
  
      password = driver.find_element(By.ID, 'pass')
      password.send_keys(&quot;password&quot;)
  
      try:
          driver.find_element(By.TAG_NAME, &quot;button&quot;).click()
          driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div[1]/div/div[2]/div[2]/div/div/div/div/div/label/input').click()
  
          #clicks the search key and searches by send_keys 
          search = driver.find_element(By.XPATH,'/html/body/div[1]/div[1]/div[1]/div/div[2]/div[2]/div/div/div/div/div/label/input')
          search.click()
          search.send_keys('The Village At Gracy Farms')
          search.send_keys(Keys.RETURN)
          print(&quot;nicee&quot;)
        
      except:
          print(&quot;failedddd&quot;)
          driver.quit(77)
  
  except:
      print(&quot;failed&quot;)
      driver.quit(22)    
  </code></pre>