title: puppeteer - how to submit form
body: <p>How do I submit the form?
  I have a simple search bar and a search button. The following enters the search string, but the click event is not fired. When headless is set to false and I manully click enter in the serachfield, the search is working. How to submit the button?</p>
  
  <pre><code>  const puppeteer = require('puppeteer');
  
  (async () =&gt; {
  const browser = await puppeteer.launch({headless: false});
  const page = await browser.newPage();
  await page.goto('http://localhost:3000', {waitUntil: 'networkidle'});
  
  await page.focus('#search');
  
  // Type our query into the search bar
  await page.type('michael');
  
  // Submit form
  await page.press('Enter');
  
  await page.screenshot({path: './screenshots/search3.png'});
  
  browser.close();
  })();
  </code></pre>
  
  <p>My searchbar</p>
  
  <pre><code>search(e) {
   e.preventDefault();
  this.props.onClick(this.props.value);}
  
  render() {
  return (&lt;form className="form-inline" id="search-form" onSubmit
  {this.search}&gt;
    &lt;div className="form-group"&gt;
      &lt;input
        type="text"
        className="form-control"
        id="search"
        value={this.props.value}
        placeholder={this.props.placeHolder}
        onChange={this.props.onChange}
      /&gt;
  
      &lt;button primary type="submit" &gt;
        {this.props.buttonText}
      &lt;/button&gt;
    &lt;/div&gt;
  &lt;/form&gt;);
  }
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p><strong>This is not working:</strong></p>
  
  <pre><code>const searchForm = await page.$('#search-form'); 
  await searchForm.evaluate(searchForm =&gt; searchForm.submit()); 
  </code></pre>
  
  <p>It does a postback and the text in the form was cleared, even though it should trigger the function with preventDefault.</p>
  
  <p>So the issue seems to be this line of code await </p>
  
  <pre><code>searchForm.evaluate(searchForm =&gt; searchForm.submit());
  </code></pre>
  
  <p><strong>This is working:</strong></p>
  
  <p>I changed the code to: </p>
  
  <pre><code>await page.click('#search-button'); 
  await page.waitForNavigation(); 
  </code></pre>