title: AngularJS: Accessing $scope objects in e2e tests
body: <p>I am building a Math tutoring application and would like to test my UI using angular's e2e testing suite.</p>
  
  <p>Currently I am working on a Fraction page that generates a random fraction, displays a series of shaded and unshaded boxes and asks the user to input the fraction formed by the shading.</p>
  
  <p>Using an <em>e2e test</em>, I would like to test how the UI responds to both correct and incorrect input; however, since the fraction is randomized on page load, I do not know what 'correct' input is from inside the test.  </p>
  
  <p>The easiest way for me to get the correct answers to input would be to gain access to the Fraction object, located at <code>$scope.problemObject</code> for the controller, and call its API functions <code>.getNumerator()</code> and <code>.getDenominator()</code>.  However, I have not found a way to get to this object from within my tests.</p>
  
  <p>Relevant lines from my controller are:</p>
  
  <pre><code>$scope.problemObject = Fraction.random();
  // This produces an object with two relevant 
  // functions (getNumerator() &amp; getDenominator())
  </code></pre>
  
  <p><strong>What I Have Tried</strong></p>
  
  <ul>
  <li><code>binding()</code></li>
  </ul>
  
  <p>Initially I thought <code>binding()</code> would do what I needed, however all calls to <code>binding('problemObject')</code> or <code>binding('problemObject.getNumerator()'</code> and the like issue an error saying that the binding cannot be found.  I suspect that this is because <code>$scope.problemObject</code> and the return value of <code>$scope.problemObject.getNumerator()</code> are not directly bound to the UI.</p>
  
  <ul>
  <li><code>angular.element().scope()</code></li>
  </ul>
  
  <p>Executing <code>angular.element('#problem').scope().problemObject</code> from the console on the page that I am testing works perfectly; however, trying the same line from within my test issues the following error: 'selectors not implemented'.</p>
  
  <p>I have also tried a few variations:</p>
  
  <p><code>element('#problem').scope().problemObject</code>: Error: 'Object # has no method 'scope''</p>
  
  <p><code>angular.element(element('#problem')).scope().problemObject</code>: Error: 'Cannot read property 'problemObject' of undefined'</p>