title: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="loginUsername"]"}
body: <p>I am trying to learn Web Scraping with Python using Selenium. I am testing Reddit.com. I am stuck here. When I run the script it stops here on the login page and gives the following error:
  (selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="loginUsername"]"})
  Please note that the same code works fine on the login page but it doesn't work on the pop up login page. It is also inside iframe. </p>
  
  <p>Here is the code:</p>
  
  <pre><code>from selenium import webdriver
  from selenium.webdriver.chrome.options import Options
  
  option = Options()
  
  option.add_argument("--disable-infobars")
  option.add_argument("start-maximized")
  option.add_argument("--disable-extensions")
  option.add_experimental_option("excludeSwitches", ['enable-automation'])
  
  # Pass the argument 1 to allow and 2 to block
  option.add_experimental_option("prefs", { 
      "profile.default_content_setting_values.notifications": 1 
  })
  driver = webdriver.Chrome(chrome_options=option, executable_path='C:\\Users\\Sheik\\Desktop\\web crawling\\chromedriver.exe')
  
  driver.get('https://www.reddit.com')
  
  # clicking on the login button
  login_btn = driver.find_element_by_xpath('//*[@id="SHORTCUT_FOCUSABLE_DIV"]/div[1]/header/div/div[2]/div[2]/div[1]/a[1]')
  login_btn.click()
  
  # calling the iFrame page
  frame = driver.find_element_by_class_name('_25r3t_lrPF3M6zD2YkWvZU')
  driver.switch_to.frame(frame)
  
  # sending the username 
  username_field = driver.find_element_by_id('loginUsername')
  username_field.click()
  username_field.send_keys('test_username')
  
  # sending the password
  password_field = driver.find_element_by_id('loginPassword')
  password_field.click()
  password_field.send_keys('test_pass')
  
  # clicking the login submit button
  submit_btn = driver.find_element_by_class_name('AnimatedForm__submitButton')
  submit_btn.click()
  </code></pre>