Skip to main content
All articles

22 December 2025 · 12 min read

Mastering Web Browser Automation: Avoiding Common Pitfalls

Learn essential tips for successful web browser automation, bypassing the complexities.

SM

Shak M

With nearly a decade of experience building integrations for SaaS tools and SMEs. I've helped companies reduce their automation maintenance burden, providing solutions that help them run more efficiently.

You've been handed a project that requires automating a web application, but there's no API available. Browser automation seems like the logical solution, but if you've worked with tools like Selenium or Puppeteer before, you know the reality: what starts as a simple automation often becomes a maintenance nightmare.

This guide will walk you through the essential strategies for successful web browser automation. You'll learn how to avoid the most expensive pitfalls, implement robust solutions, and decide when to build versus when to leverage existing solutions.

What is Web Browser Automation?

Web browser automation (also called UI automation or headless browser testing) allows you to programmatically control a web browser to simulate human interactions. This includes clicking buttons, filling forms, extracting data, and navigating between pages without manual intervention.

Unlike API integrations that communicate directly with an application's backend, browser automation works at the interface level. Tools like Selenium WebDriver, Puppeteer, and Playwright control actual browser instances to interact with web pages just as a human user would.

Common Applications

  1. Data Extraction and Web Scraping - Pull pricing data from competitor websites, extract lead information from directories, or gather market research when target sites don't offer data export features or API access.

  2. Form Submissions and Data Entry - Automatically submit forms across multiple platforms or transfer data between systems that don't integrate natively. Particularly valuable for high-volume repetitive tasks.

  3. Automated Testing - Test web applications across different browsers and screen sizes, validate user flows end-to-end, or perform regression testing.

  4. Account Management - Check account statuses across multiple platforms, monitor for specific changes or alerts, or perform routine maintenance tasks.

  5. Legacy System Integration - Bridge the gap between modern workflow tools and older web applications that were never designed with automation in mind.

Browser Automation vs API Integration

While API integrations should always be your first choice when available, understanding the distinctions helps you make informed decisions:

Factor

API Integration

Browser Automation

Setup Complexity

Low to medium

Medium to high

Execution Speed

Fast (milliseconds)

Slower (seconds to minutes)

Reliability

Very high (99%+)

Lower (85-95%)

Maintenance

Minimal

Ongoing (UI changes)

Resource Usage

Lightweight

Heavy (browser instances, memory)

Authentication

API keys, OAuth

Credentials, session management, MFA

Best For

Available APIs

No API or limited functionality

When Should You Choose Browser Automation?

Applications Without APIs

Despite the rise of API-first architecture, approximately 35-40% of business software applications still lack comprehensive API coverage. This includes vertical SaaS platforms, older enterprise systems, and niche tools built before modern integration standards.

Incomplete or Restrictive API Access

Sometimes an API exists but doesn't expose the functionality you need. Common limitations include read-only access when you need to create records, missing endpoints for specific features, rate limits too restrictive for your use case, or premium API tiers that are cost-prohibitive.

When NOT to Choose Browser Automation

Be honest about these red flags: the API exists and covers your needs (use it instead), the task is simple enough that manual work is faster, the website has aggressive anti-bot measures, real-time synchronization is critical, or your team lacks the technical skills to maintain the solution.

The 7 Most Expensive Mistakes in Browser Automation

1. Ignoring Dynamic Content and AJAX Requests

The Problem:

Modern web applications built with React, Vue, or Angular load data asynchronously. When your automation runs, the browser might report the page as "loaded," but the specific elements you need haven't rendered yet. Without proper wait strategies, your script tries to interact with elements before they exist, creating "flaky" automation that works 70% of the time but fails unpredictably.

Real-World Example:

A financial dashboard loads navigation instantly but fetches transaction data via API calls. Your script clicks "Export" before the data populates, resulting in an empty export file. The automation appears to work but delivers incorrect results.

The Solution with Puppeteer:

javascript

// Bad: Fixed delay (slow and unreliable)
await page.click('#load-data-button');
await page.waitForTimeout(5000); // Might be too short or too long
await page.click('#export-button');

// Good: Wait for specific element to be visible
await page.click('#load-data-button');
await page.waitForSelector('#data-table', {
  visible: true,
  timeout: 10000
});
await page.click('#export-button');

// Better: Wait for multiple conditions
await page.click('#load-data-button');
await Promise.all([
  page.waitForSelector('#data-table', { visible: true }),
  page.waitForSelector('.loading-spinner', { hidden: true }),
  page.waitForFunction(() => {
    return document.querySelector('#row-count').textContent !== '0';
  })
]);
await page.click('#export-button');

// Best: Wait for network idle (all AJAX complete)
await page.click('#load-data-button');
await page.waitForNetworkIdle({ idleTime: 500 });
await page.click('#export-button');

The Impact:

Teams typically spend 30-40% of their maintenance time debugging timing-related failures. For a team maintaining 20 automations, this can easily consume 20-30 hours per month.

Hosted Solution: Clickr workflows include intelligent wait strategies that automatically detect when elements are ready for interaction, reducing failures from timing issues by over 90%.

2. Underestimating Multi-Factor Authentication Complexity

The Problem:

MFA has become standard security practice, with adoption rates exceeding 80% among enterprise SaaS applications. Common authentication methods each present unique challenges: SMS codes require phone access, authenticator apps generate codes that expire in 30-60 seconds, email verification requires checking another system, and push notifications require mobile device interaction.

Real-World Example:

An ops team builds automation to extract monthly reports from their accounting software. It works perfectly in development (MFA disabled), but fails in production when the MFA prompt appears. The team must manually authenticate every time the session expires (typically every 24 hours).

Solutions:

For TOTP (authenticator app) codes, you can generate them programmatically:

javascript

import * as OTPAuth from 'otpauth';

// Store the secret securely (environment variable)
const totp = new OTPAuth.TOTP({
  issuer: 'YourApp',
  label: 'account@example.com',
  algorithm: 'SHA1',
  digits: 6,
  period: 30,
  secret: process.env.TOTP_SECRET
});

// Generate current code
const code = totp.generate();

// Use in automation
await page.type('#mfa-code', code);
await page.click('#verify-button');

For session persistence:

javascript

// Save authenticated session
const cookies = await page.cookies();
fs.writeFileSync('session.json', JSON.stringify(cookies));

// Restore session later (avoid re-authentication)
const savedCookies = JSON.parse(fs.readFileSync('session.json'));
await page.setCookie(...savedCookies);

Hosted Solution: Clickr workflows handle MFA through persistent session management and intelligent re-authentication, supporting OTP without requiring you to manage secrets or phone numbers.

3. Neglecting Long-Term Maintenance Costs

The Problem:

The initial build is just the beginning. Websites change constantly through UI redesigns, framework updates, feature rollouts, and security enhancements. All of these break existing automations.

The True Cost:

Timeframe

DIY Maintenance

Cost at $100/hr

Infrastructure

Total

Initial build

20-40 hours

$2,000-4,000

$0

$2,000-4,000

Year 1

8-16 hours

$800-1,600

$600-1,200

$1,400-2,800

Year 2

15-30 hours

$1,500-3,000

$600-1,200

$2,100-4,200

Year 3

15-30 hours

$1,500-3,000

$600-1,200

$2,100-4,200

3-Year Total

58-116 hours

$5,800-11,600

$1,800-3,600

$7,600-15,200

Solutions:

Build for resilience from day one by using stable selectors (data-testid attributes when possible), implementing fallback selector strategies, building modular code that isolates UI interactions, and establishing monitoring and alerting.

Hosted Solution: Clickr eliminates maintenance burden entirely. When websites change, Clickr's team updates the workflows. You receive the benefits without the ongoing cost.

4. Choosing Fragile Selectors

The Problem:

Element selectors are how your automation finds specific parts of a webpage. Choosing the wrong selectors makes your automation brittle and prone to breaking.

Selector Stability Ranking:

  1. Most Stable: [data-testid="submit-button"] (purpose-built for testing)

  2. Very Stable: #submit-button (unique IDs)

  3. Moderately Stable: button[name="submit"] (semantic + attributes)

  4. Unstable: .btn-primary-lg (CSS classes change during redesigns)

  5. Very Unstable: div.container > div.row > button:nth-child(3) (breaks when structure changes)

Solution with Puppeteer:

javascript

// Bad: Auto-generated CSS classes
await page.click('.css-1dbjc4n.r-1awozwy.r-18u37iz');

// Good: Fallback selector strategy
async function clickWithFallback(page, selectors) {
  for (const selector of selectors) {
    try {
      await page.waitForSelector(selector, { timeout: 2000 });
      await page.click(selector);
      return; // Success
    } catch (e) {
      continue; // Try next selector
    }
  }
  throw new Error('Element not found with any selector');
}

// Usage: Try stable selectors first, fall back to less stable
await clickWithFallback(page, [
  '[data-testid="submit-button"]',
  '#submit-button',
  'button[name="submit"]',
  'button[type="submit"]',
  'button:has-text("Submit")'
]);

Best Practice: Avoid nth-child selectors, never use auto-generated class names, and document why each selector was chosen.

5. Poor Error Handling and Retry Logic

The Problem:

Network hiccups, slow server responses, and temporary outages are inevitable. Scripts without proper error handling fail completely at the first problem, even if a simple retry would have succeeded.

Solution with Puppeteer:

javascript

// Exponential backoff retry pattern
async function retryWithBackoff(fn, maxRetries = 3, initialDelay = 1000) {
  for (let attempt = 0; attempt < maxRetries; attempt++) {
    try {
      return await fn();
    } catch (error) {
      if (attempt === maxRetries - 1) throw error;
      
      const delay = initialDelay * Math.pow(2, attempt);
      console.log(`Attempt ${attempt + 1} failed, retrying in ${delay}ms...`);
      await new Promise(resolve => setTimeout(resolve, delay));
    }
  }
}

// Usage
await retryWithBackoff(async () => {
  await page.goto('https://example.com');
  await page.waitForSelector('#content', { timeout: 5000 });
});

// Graceful degradation with fallbacks
async function extractData(page) {
  try {
    // Try primary method
    return await extractViaTable(page);
  } catch (e) {
    console.log('Primary method failed, trying fallback');
    try {
      // Try alternative method
      return await extractViaExport(page);
    } catch (e2) {
      console.log('Both methods failed, returning partial data');
      return await extractBasicInfo(page); // Return something rather than nothing
    }
  }
}

The Impact: For an automation running daily, even a 5% transient failure rate means 1-2 interventions per month, or 12-24 hours per year of unnecessary manual work.

6. Not Planning for Anti-Bot Detection

The Problem:

Websites increasingly employ sophisticated techniques to detect and block automated traffic. Common detection methods include browser fingerprinting, mouse movement analysis, timing patterns, request headers, JavaScript challenges, CAPTCHA, and IP reputation checks.

Solutions with Puppeteer:

javascript

import puppeteer from 'puppeteer-extra';
import StealthPlugin from 'puppeteer-extra-plugin-stealth';

// Use stealth plugin to avoid detection
puppeteer.use(StealthPlugin());

const browser = await puppeteer.launch({
  headless: 'new', // Use new headless mode
  args: [
    '--disable-blink-features=AutomationControlled',
    '--no-sandbox',
    '--disable-setuid-sandbox'
  ]
});

const page = await browser.newPage();

// Randomize viewport
await page.setViewport({
  width: 1920 + Math.floor(Math.random() * 100),
  height: 1080 + Math.floor(Math.random() * 100)
});

// Add human-like delays
function humanDelay(min = 500, max = 2000) {
  const delay = Math.random() * (max - min) + min;
  return new Promise(resolve => setTimeout(resolve, delay));
}

// Use in automation
await page.goto('https://example.com');
await humanDelay();
await page.click('#button1');
await humanDelay(1000, 3000);
await page.type('#input1', 'text', { delay: 100 }); // Humanlike typing

Important: Always ensure your automation complies with the website's Terms of Service, respects robots.txt directives, and doesn't overload servers.

7. Building When You Should Buy

The Problem:

Teams focus on initial build costs while underestimating the total cost of ownership over 2-3 years.

Build vs. Buy Decision Matrix:

Factor

Build In-House

Use Hosted Solution

Initial time

20-40 hours

1-2 hours

Monthly maintenance

4-20 hours

0 hours

Infrastructure

Required

Included

MFA handling

Complex

Built-in

Website changes

Your responsibility

Provider handles

Best for

Highly custom logic

Standard workflows

Break-even

N/A

6-12 months

When to Build: Highly custom business logic, security requirements necessitating on-premise execution, you're automating internal applications where you control changes, or you have dedicated automation engineers.

When to Buy: Standard workflows (data extraction, form submission), your expertise is integration logic not browser automation maintenance, applications change frequently, or time-to-value is critical.

Explore Clickr's workflow marketplace to see if the automation you need already exists.

Best Practices for Success

Test Regularly

Run automations on a schedule in test environments, perform smoke tests after application updates, and maintain test data sets that cover edge cases.

Monitor Everything

Track success rates, execution times, error frequencies, and resource usage. Set up alerting for immediate failures, degraded performance, and infrastructure issues. Use tools like Datadog, New Relic, or Grafana.

Optimize for Maintainability

Use descriptive names, add comments explaining selector choices, follow consistent code organization patterns, implement the Page Object Model pattern, and separate business logic from UI interaction code.

Handle Sessions Efficiently

Store authenticated session cookies, implement session refresh logic before expiration, and use persistent browser profiles. Balance security and convenience by rotating credentials periodically and storing secrets securely.

Document Everything

Document business purpose, technical architecture, dependencies, error handling strategies, and maintenance history. Create operational documentation for deployment, monitoring, troubleshooting, and team onboarding.

Frequently Asked Questions

How much does browser automation maintenance cost?

For a single automation of moderate complexity, expect 4-20 hours of monthly maintenance. At $100/hour developer rates, this translates to $400-2,000 per month, or $4,800-24,000 per year, not including infrastructure ($50-200/month) and monitoring tools ($50-180/month).

Using Clickr eliminates maintenance costs entirely, typically providing better ROI after 6-12 months.

Can browser automation handle multi-factor authentication?

Yes, but it requires sophisticated implementation. TOTP-based authenticator apps can be handled programmatically if you have the shared secret. SMS-based MFA is more challenging and typically requires session persistence strategies.

Clickr workflows include built-in MFA handling that manages OTP authentication and session persistence automatically.

What happens when a website redesign breaks my automation?

Website changes are the primary cause of automation failures. Expect to spend anywhere from a few hours (if only selectors changed) to rebuilding completely (if workflow structure changed). Automations using stable selectors, modular code, and comprehensive logging break less frequently.

With Clickr, the maintenance team updates workflows proactively, often before you experience failures.

How do I choose between Selenium, Puppeteer, or a hosted solution?

Choose Selenium for cross-browser testing and multi-language support (Python, Java, C#, Ruby).

Choose Puppeteer/Playwright for modern JavaScript development with Chrome/Chromium, better built-in features, and auto-waiting.

Choose Clickr if your expertise is integration logic (not browser automation maintenance), you want zero maintenance burden, you need MFA handling without complex implementation, or time-to-value is critical.

How can I handle dynamic websites with JavaScript?

Implement explicit waits using your framework's built-in capabilities. Avoid fixed delays as they make automation slower and less reliable. See the Puppeteer examples in the "Ignoring Dynamic Content" section above for specific implementation patterns.

Is browser automation reliable for production?

Well-implemented automation achieves 95-99% success rates for stable applications. Reliability depends on stable selectors, comprehensive error handling, regular maintenance, and monitoring. APIs offer 99.9%+ reliability, while even well-maintained browser automation typically maxes out at 95-98%.

Clickr achieves higher reliability through dedicated maintenance and continuous monitoring.

How do I secure credentials in browser automation?

Never hardcode credentials. Use environment variables, secrets management services (AWS Secrets Manager, Azure Key Vault, HashiCorp Vault), or encrypted configuration files. Follow the principle of least privilege with dedicated service accounts, regular credential rotation, and limited session lifetimes.

What's the learning curve?

For developers with web experience: 1-2 weeks for basic automation, 3-6 months for production-ready implementations. For no-code tool users: 1-2 days with visual tools. Using Clickr bypasses the learning curve entirely, requiring only standard API integration skills.

Conclusion

Web browser automation unlocks access to applications without APIs, but requires significantly more maintenance than API integrations. The seven mistakes covered here (ignoring dynamic content, underestimating MFA, neglecting maintenance costs, choosing fragile selectors, poor error handling, not planning for anti-bot detection, and building when you should buy) account for the majority of failed automation projects.

Making Your Decision

Build in-house if you're automating internal applications where you control the UI, have dedicated automation engineers with capacity for maintenance, or the automation is core to your product offering.

Use a hosted solution if you're automating third-party applications that change without notice, your expertise is integration logic rather than browser automation internals, you need reliable workflows without dedicated maintenance resources, or time-to-value is critical.

Ready to eliminate maintenance? Explore Clickr's human-maintained workflows or view our API documentation to get started in minutes.

You might also like

Handling Multi-Factor Authentication in UI Automation: Strategies & Implementation

Learn how to automate workflows protected by multi-factor authentication without sacrificing security. Technical guide with real-world strategies and code examples.

27 December 2025 · 19 min read

Make.com API Limitations: How to Automate Tools Without APIs in 2026

Discover how automation consultants overcome Make.com API limitations when integrating tools without APIs. Compare build vs buy solutions, costs, and maintenance strategies.

24 December 2025 · 25 min read

Connect a system and start reading your data

Sign in with the account you already have, choose the datasets and actions you need, and make your first request the same day. Cancel at any time.

Start free trial
Talk to us