title: NoSuchElementException: Message: no such element: Unable to locate element: {"method":"id","selector":"username"}
body: <p>Here's the method I wrote with selenium to login to my webpage:</p>
  
  <pre><code>def login(self, username, password):
      driver.switch_to.default_content()
      driver.switch_to.frame("iframe")
      driver.find_element_by_id("username").send_keys(username)
      driver.find_element_by_id("password").send_keys(password)
      driver.find_element_by_id("loginButton").click()
  </code></pre>
  
  <p>Here's the code I have in Robot Framework:</p>
  
  <pre><code>*** Settings ***
  Library           CustomSelenium2Plus.py
  
  *** Test Cases ***
  SR Create New Service
      Open Browser    https://partner.sdg.msg.lab.t-mobile.com/tpim/    Chrome
      ${webdriver}=    Get webdriver instance
      Set Driver    ${webdriver}
      Login    usrnm    pwd
      ...
      Delete Service
      Close Browser
  </code></pre>
  
  <p><code>CustomSelenium2Plus.py</code> is a custom library I wrote that subclasses RobotFramework's Selenium2Library and is where the login method is located. The method is totally functional when I call it the first time with the <code>Login</code> Keyword. However, it throws a <code>NoSuchElementException</code> when it's called a second time within <code>Delete Service</code> Keyword's function which looks like this:</p>
  
  <pre><code>def delete_service(self):
      self.logout()
      self.login("usrnm", "pwd")
      ...
  </code></pre>
  
  <p>I've already checked that the frame is correct. I've also already tried having my <code>WebDriver</code> wait for the visibility of both the iframe and the username textarea, an implicit <code>WebDriverWait</code>, and a <code>time.sleep(30)</code>.</p>
  
  <p>EDIT: The HTML code isn't mine and pretty ugly but here's a screencap</p>
  
  <p><a href="https://i.stack.imgur.com/dKeOo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dKeOo.png" alt="enter image description here"></a></p>
  
  <p>There are technically four iframes nested within each other but calling <code>driver.switch_to.frame("iframe")</code> any more than once throws a <code>NoSuchFrameException</code></p>