title: Using selenium to get element by id in python testing
body: <p>In my html code below:</p>
  
  <pre><code>&lt;div class="collapse navbar-collapse" id="b-menu-1"&gt;
                      &lt;ul class="nav navbar-nav navbar-right"&gt;
  
  
                          &lt;li&gt;&lt;a href="/accounts/login/"&gt;Sign In&lt;/a&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;a href="/accounts/signup/"&gt;Sign Up&lt;/a&gt;&lt;/li&gt;
  
  
                          {% if request.user.is_authenticated or logged_in %}
                          &lt;li class="dropdown"&gt;
                              &lt;a href="#" class="dropdown-toggle" data-toggle="dropdown"&gt;
                                  &lt;span class="glyphicon glyphicon-user"&gt;&lt;/span&gt;&lt;b class="caret"&gt;&lt;/b&gt;&lt;/a&gt;
  
                              &lt;ul class="dropdown-menu"&gt;
                                  &lt;li&gt;&lt;a href="/accounts/manageAccount/"&gt;Manage Account&lt;/a&gt;&lt;/li&gt;
                                  &lt;li&gt;&lt;a href="/accounts/createProfile/"&gt;create profile&lt;/a&gt;&lt;/li&gt;
                                  &lt;li&gt;&lt;a href="/accounts/viewProfile/"&gt;view profile&lt;/a&gt;&lt;/li&gt;
                                  &lt;li&gt;&lt;a href="/accounts/editProfile/"&gt;edit profile&lt;/a&gt;&lt;/li&gt;  
                                  &lt;li&gt;&lt;a href="/accounts/logout/" id="logout"&gt;Log out&lt;/a&gt;&lt;/li&gt;
                              &lt;/ul&gt;
                          &lt;/li&gt;
  
  
                          &lt;li data-toggle="modal" data-target="#my-modal-box" class="active"&gt;
                              &lt;a href="#"&gt;&lt;span class="glyphicon glyphicon-search"&gt; Search&lt;/a&gt;&lt;/li&gt;
                      &lt;/ul&gt;
                  &lt;/div&gt; 
  </code></pre>
  
  <p>I want to select the logout button which is actually appears in a selector in my nav bar.</p>
  
  <p>I tried getting element by name , id etc but nothin worked out.</p>
  
  <pre><code>elem2 = self.driver.find_element_by_id("logout")
  elem2.send_keys(Keys.RETURN)
  </code></pre>
  
  <p>I explicitly added id in a href link for logout , but could not grab the element. Any suggestion how can I get the logout element </p>
  
  <p>I get below exception:</p>
  
  <pre><code>NoSuchElementException: Message: u'Unable to locate element: {"method":"id","selector":"logout"}' ; Stacktrace: 
      at FirefoxDriver.prototype.findElementInternal_ (file:///tmp/tmpPHM5S7/extensions/fxdriver@googlecode.com/components/driver_component.js:8905)
      at FirefoxDriver.prototype.findElement (file:///tmp/tmpPHM5S7/extensions/fxdriver@googlecode.com/components/driver_component.js:8914)
      at DelayedCommand.prototype.executeInternal_/h (file:///tmp/tmpPHM5S7/extensions/fxdriver@googlecode.com/components/command_processor.js:10884)
      at DelayedCommand.prototype.executeInternal_ (file:///tmp/tmpPHM5S7/extensions/fxdriver@googlecode.com/components/command_processor.js:10889)
      at DelayedCommand.prototype.execute/&lt; (file:///tmp/tmpPHM5S7/extensions/fxdriver@googlecode.com/components/command_processor.js:10831) 
  </code></pre>