Testing mobile browsers with Selenium is often harder than desktop automation. Mobile sites render differently across devices, browser versions, and screen sizes, which means a script that works on one setup may fail on another. Debugging also takes longer when touch gestures and mobile-specific pop-ups come into play.
A proper setup using Android SDK, Node.js, and Appium makes it possible to handle these challenges. With the right configuration, Selenium tests can replicate real user conditions and expose issues that standard desktop testing would miss.
This article shows how to set up Selenium mobile browser automation step by step.
Selenium is widely used for browser automation, but its application on mobile requires a different approach. Desktop browsers rely on WebDriver directly, while mobile browsers need additional components like Appium to bridge the gap between Selenium and the device.
Mobile browser testing with Selenium focuses on verifying how web applications behave when accessed from real smartphones. This includes checking layout across screen sizes, validating touch interactions, and ensuring performance under mobile network conditions.
Here are the core aspects you need to know:
Desktop-first testing often misses problems that show up only on mobile browsers. Differences in rendering engines, viewport handling, and device resources create bugs that do not appear in desktop runs.
Here are the key reasons teams rely on Selenium for mobile browser testing include:
Before writing any scripts, you need to prepare the environment that connects Selenium with mobile browsers. Each layer of the setup serves a specific role, and missing one will cause tests to either fail silently or not run at all. At a minimum, you need tools that let Selenium talk to mobile devices, manage dependencies, and execute browser commands.
The setup involves three parts:
The Android SDK provides platform tools that allow your machine to recognize and communicate with Android devices. Without it, Appium cannot send commands from Selenium WebDriver to a real device or emulator.
Here is what you need to do:
Node.js is required to run Appium, and Appium is the bridge that translates Selenium commands into mobile actions. Without these two components, Selenium cannot communicate with a mobile browser.
Here’s how to set them up:
Once the Android SDK and Appium server are ready, you can validate the setup with a simple Selenium test. Make sure the device is connected or an emulator is running, Appium is started at http://localhost:4723, and the correct ChromeDriver is installed for the browser version on the device.
The script below opens Chrome on the device, navigates to a page, checks for a visible element, and then quits. Running this confirms that Selenium commands are being executed on the mobile browser.
// sample-mobile-test.js
const {Builder, By, until} = require('selenium-webdriver');
(async function mobileChromeTest() {
const caps = {
platformName: 'Android',
deviceName: 'Android Device',
browserName: 'Chrome',
automationName: 'UiAutomator2'
};
const driver = await new Builder()
.usingServer('http://localhost:4723/wd/hub')
.withCapabilities(caps)
.build();
try {
await driver.get('https://example.com');
const el = await driver.wait(until.elementLocated(By.css('h1')), 10000);
console.log('Page H1 text:', await el.getText());
} finally {
await driver.quit();
}
})();
If the test runs successfully and the Appium logs show a session creation, the setup is complete and ready for more advanced cases.
A single mobile browser check is not enough. Each browser engine has its own quirks that can break core user flows. Teams often discover that code passing Chrome tests fails for Safari or older Android browsers. Running Selenium tests across multiple browsers highlights these issues before they reach production.
Here are the critical reasons:
One platform that helps address these cross-browser testing issues is BrowserStack. It provides access to thousands of real mobile devices and browsers in the cloud, so you do not need to maintain a device lab. Because the testing runs on actual hardware, layout bugs, rendering glitches, and touch issues are easier to catch than when using emulators or simulators.
BrowserStack also supports parallel test execution, integrates with CI/CD pipelines, and provides debugging features such as logs, screenshots, and video recordings to help trace failures faster.
Even with a proper setup, mobile browser tests in Selenium often fail for reasons that are specific to mobile environments. These failures can waste time if not identified early.
Some of the most frequent issues include:
Mobile browser testing adds variables that make failures more likely, but many of these issues can be controlled with the right practices. Reliability improves when tests account for network delays, device conditions, and browser differences.
Here are some proven approaches:
BrowserStack helps with many of these practices by offering updated browsers on real devices, along with logs, screenshots, and video recordings that make it easier to diagnose flaky failures.
Selenium mobile browser automation makes it possible to test how users actually experience web applications on real devices and browsers. Setting up the environment with Android SDK, Node.js, and Appium ensures that tests run reliably, while cross-browser checks catch rendering and feature issues that appear only under certain conditions.
Run Selenium Tests on Cloud
Get visual proof, steps to reproduce and technical logs with one click
Continue reading
Try Bird on your next bug - you’ll love it
“Game changer”
Julie, Head of QA
Try Bird later, from your desktop