title: Get text field info out of loaded webpage - Mac OS X Development
body: <p>I am a newbie in the Mac world.</p>
  
  <p>I need to create an app that is able to extract information entered on a web page, from text fields. My app will load a webpage hosted somewhere, and within the webpage there will be a a series of text fields and a submit button. Once the button is clicked, I must be able to read the information entered into the text fields of this webpage.</p>
  
  <p>I have code as follows:</p>
  
  <pre><code>+ (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector
  {
  // For security, you must explicitly allow a selector to be called from JavaScript.
  
  if (aSelector == @selector(showMessage:)) {
      return NO; // i.e. showMessage: is NOT _excluded_ from scripting, so it can be called.
  }
  
  return YES; // disallow everything else
  }
  
  - (void)showMessage:(NSString *)message
  {
      // This method is called from the JavaScript "onClick" handler of the INPUT element 
      // in the HTML. This shows you how to have HTML form elements call Cocoa methods.
  
    DOMDocument *myDOMDocument = [[webView mainFrame] DOMDocument];     // 3
    DOMElement *contentTitle = [myDOMDocument getElementById:@"TexTest"];   // DOM
    message = [[contentTitle firstChild] nodeValue];                                            // lines
  
    NSRunAlertPanel(@"Message from JavaScript", message, nil, nil, nil);
  }
  </code></pre>
  
  <p>When I run the app, and it gets to NSRunAlertPanel, it does not want to execute further.</p>
  
  <p>When I comment the 3 DOM lines out, the NSRunAlertPanel shows its message and I can continue.</p>
  
  <p>The HTML looks like this:</p>
  
  <pre><code>&lt;body&gt; 
    &lt;h1 id="contentTitle"&gt;Some kind of title&lt;/h1&gt;
    &lt;div id="main_content"&gt; 
      &lt;p&gt;Some content&lt;/p&gt; 
      &lt;p&gt;Some more content&lt;/p&gt; 
    &lt;/div&gt; 
    &lt;div&gt;
      &lt;input id="TexTest" value=" " type="text"&gt;
    &lt;/div&gt; 
    &lt;div&gt;
      &lt;input id="message_button" value="Show Message" onclick="window.AppController.showMessage_('Hello there...');" type="button"&gt;
    &lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>Anybody able to assist in this matter?</p>