title: Protractor Find and Click Element
body: <p>I have a pretty simple setup.  I need to be able to find a link and click it.  But whenever I find it and <code>click()</code> it i get</p>
  
  <blockquote>
    <p>StaleElementReferenceError: stale element reference: element is not attached to the page document</p>
  </blockquote>
  
  <p>Can someone explain to me what I am doing wrong?  If I target it via css it works fine.  Its only when I used the protractor extensions that it fails.  Nothing is changing on the page and I have tried doing a "waitForAngular" as well as a long timeout.  Same result.</p>
  
  <pre><code>&lt;li ng-click="getLocation(l)" class="" ng-repeat="l in location"  &gt;
     &lt;div class="location_name"&gt;{{ l.LocationID }} - {{l.LocationName}}&lt;/div&gt;
  &lt;/li&gt;
  </code></pre>
  
  <hr>
  
  <pre><code>var locations= element.all(
      by.binding('{{l.LocationName}}'))
      .each(function(item){
          item.getText().then(function(text){
              if(text == name){
                  console.log("found", item);
                  item.click()
                  console.log("clicked")
                  found = true;
              }
          });
      });
  </code></pre>
  
  <p>An added plus would be to explain to me how to get the debugger working.   I'm using the latest version of protractor(0.20.1)</p>
  
  <blockquote>
    <p>Failed to open socket on port 5858, waiting 1000 ms before retrying</p>
  </blockquote>
  
  <p><strong>Ex Dump</strong></p>
  
  <pre><code>StaleElementReferenceError: stale element reference: element is not attached to the page document
    (Session info: chrome=33.0.1750.146)
    (Driver info: chromedriver=2.9.248307,platform=Mac OS X 10.9.1 x86_64) (WARNING: The server did not provide any stacktrace information)
  Command duration or timeout: 5 milliseconds
  For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
  Build info: version: '2.40.0', revision: 'fbe29a9', time: '2014-02-19 20:54:28'
  System info: host: '.home', ip: '192.168.1.2', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.1', java.version: '1.6.0_65'
  Session ID: 935f7630f50d9b1b4c8da73261e54153
  Driver info: org.openqa.selenium.chrome.ChromeDriver
  Capabilities [{platform=MAC, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=/var/folders/qj/xvhg6hv5245cryry73wygbkw0000gn/T/.org.chromium.Chromium.b5z7Xe}, rotatable=false, locationContextEnabled=true, version=33.0.1750.146, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, nativeEvents=true, webStorageEnabled=true, applicationCacheEnabled=false, takesScreenshot=true}]
     Stacktrace:
       Error
      at null.&lt;anonymous&gt; (/Users//work////selenium/spec/locationsSpec.js:21:3)
      at Object.&lt;anonymous&gt; (/Users//work////selenium/spec/locationsSpec.js:7:1)
  At async task:
        StaleElementReferenceError: stale element reference: element is not attached to the page document
    (Session info: chrome=33.0.1750.146)
    (Driver info: chromedriver=2.9.248307,platform=Mac OS X 10.9.1 x86_64) (WARNING: The server did not provide any stacktrace information)
  Command duration or timeout: 5 milliseconds
  For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
  Build info: version: '2.40.0', revision: 'fbe29a9', time: '2014-02-19 20:54:28'
  System info: host: '.home', ip: '192.168.1.2', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.1', java.version: '1.6.0_65'
  Session ID: 935f7630f50d9b1b4c8da73261e54153
  Driver info: org.openqa.selenium.chrome.ChromeDriver
  Capabilities [{platform=MAC, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=/var/folders/qj/xvhg6hv5245cryry73wygbkw0000gn/T/.org.chromium.Chromium.b5z7Xe}, rotatable=false, locationContextEnabled=true, version=33.0.1750.146, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, nativeEvents=true, webStorageEnabled=true, applicationCacheEnabled=false, takesScreenshot=true}]
  ==== async task ====
  WebElement.getText()
      at element.(anonymous function) [as getText] (/Users//work////selenium/node_modules/protractor/lib/protractor.js:599:32)
      at /Users//work////selenium/helpers/locations.js:10:18
      at /Users//work////selenium/node_modules/protractor/lib/protractor.js:367:11
      at Array.forEach (native)
      at /Users//work////selenium/node_modules/protractor/lib/protractor.js:366:13
  ==== async task ====
  asynchronous test function
  </code></pre>