title: How to use Apify to log in to a site and click a button?
body: <p>I need use <a href="http://www.apify.com" rel="nofollow noreferrer">Apify</a> and <a href="http://www.zapier.com" rel="nofollow noreferrer">Zapier</a> to automate i) logging-in to a password-protected web page and ii) clicking a button. How can I do this?</p>
  
  <p>I think I should be using Puppeteer in Actor, but I'm not certain how.</p>
  
  <p>Target URLs will change from time to time. Their format is <code>https://studio.example.com/products/videocloud/media/videos/{id_code}</code> where <code>{id_code}</code> is, for example, <code>6091481925001</code>.</p>
  
  <h1>1. Zapier</h1>
  
  <p>Zapier should invoke an Apify Actor to do the work. An action in an existing zap already has access to the dynamic <code>{id_code}</code>. An additional action should "Run Actor" to Apify, passing either <code>{id_code}</code> or full URL <code>https://studio.example.com/products/videocloud/media/videos/6091481925001</code> to Apify to run on.</p>
  
  <p><strong>How do I properly pass the value to Apify through "Input Body"?</strong></p>
  
  <p><a href="https://i.stack.imgur.com/aiNC6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aiNC6.png" alt="enter image description here"></a></p>
  
  <h1>2. Login</h1>
  
  <p>When accessed whilst unauthenticated, the page redirects to a login form at <code>https://signin.example.com/?redirect=https%3A%2F%2Fstudio.example.com%2Fproducts%2Fvideocloud%2Fmedia%2Fvideos%2F6091481925001</code> with: </p>
  
  <ul>
  <li>"Email Address" (<code>input</code> with <code>id="email"</code> and <code>name="email"</code>)</li>
  <li>"Password" (<code>input</code> with <code>id="password"</code> and <code>name="password"</code>)</li>
  <li>"Sign In" button (<code>button</code> with <code>id="signinButton"</code> and <code>type="submit"</code>)</li>
  </ul>
  
  <p><strong>How do I use an Actor to log in here?</strong></p>
  
  <p><a href="https://i.stack.imgur.com/I4xVi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/I4xVi.png" alt="enter image description here"></a></p>
  
  <h1>3. Click</h1>
  
  <p>Once authenticated, the target page appears. It has a button bar including the button "Activate" (<code>button</code> whose child <code>span</code> text must only be "Activate" if we are allowed to click it).</p>
  
  <p>(For info - once clicked, the button text should become "Deactivate").</p>
  
  <p><strong>How do I get Apify to click the "Activate" button here?</strong></p>
  
  <p><a href="https://i.stack.imgur.com/rWTdW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rWTdW.png" alt="enter image description here"></a></p>
  
  <p>As I understand it, this is not a <em>scraping</em> job, since I am not looking to return data from the web page, so I should not be using <a href="https://apify.com/apify/puppeteer-scraper" rel="nofollow noreferrer">apify/puppeteer-scraper</a> or <a href="https://apify.com/docs/scraping/tutorial/web-scraper" rel="nofollow noreferrer">apify/web-scraper</a>.</p>
  
  <h1>Update:</h1>
  
  <p>So far, I have the following. However, Puppeteer inside Apify times out - at fairly lengthy values up to 9000ms, suggesting it isn't necessarily a page-load issue (?)</p>
  
  <pre><code>const Apify = require('apify');
  
      Apify.main(async () =&gt; {
  
  
  
          // Get credentials
          const { EMAIL, PASSWORD } = Apify.getEnv();         // Docs for using values: https://apify.com/docs/actor#source-env-vars
  
  
          // Launch Puppeteer
          const browser = await Apify.launchPuppeteer();
          const page = await browser.newPage();
          await page.goto('https://signin.example.com/login');
  
          // Login
          await page.type('#email', process.env.EMAIL);
          console.log('Attempted to enter email');
  
          await page.type('#password', process.env.PASSWORD);
          console.log('Attempted to enter password');
  
          await page.click('#signinButton');
          console.log('Attempted to click button');    
  
          // Times-out here
  
          await page.waitForNavigation();
          console.log('Attempted to wait for navigation');
  
          // Get cookies
          const cookies = await page.cookies();
          console.log('Attempted to wait for cookies');
  
          await browser.close();
  
          console.log('Done.');
  
  
      });
  </code></pre>