Appium and Selenium testing tips diagram covering explicit waits, locator strategies, cross-platform testing, and Appium capabilities.

Appium and Selenium Testing: Essential Tips & Tricks for 2026

Selenium and Appium are two of the most popular open-source automation tools. Selenium is the industry standard for web application testing, while Appium is the go-to choice for mobile app testing across Android and iOS. Bundled with powerful features, both tools are highly recommended for software testing. However, to get the most out of them, you need a proper understanding of their capabilities and common pitfalls.

This guide compiles essential tips and tricks for Selenium and Appium, helping you write more stable, efficient, and maintainable tests in 2026.

For a broader view of test automation, read our guide on 7 Tips for Developing the Ultimate Test Automation Strategy.

Part 1: Selenium WebDriver Tips & Tricks

Selenium WebDriver is the core of browser automation. These tips will help you avoid common mistakes and write more reliable tests.

1. Use Explicit Waits (Avoid Thread.sleep)

Using Thread.sleep() is a common anti-pattern. It pauses execution for a fixed time, regardless of whether the element is ready. This leads to slow tests (if the element loads faster) or flaky failures (if it loads slower).

Better approach:

  • WebDriverWait: Polls the DOM every 500ms until the condition is met or a timeout occurs.
  • FluentWait: More flexible; allows you to configure polling frequency and ignore specific exceptions.
  • ExpectedConditions: Provides pre-built conditions like elementToBeClickablevisibilityOfElementLocated, and presenceOfElementLocated.

Example (Java):

java

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
wait.until(ExpectedConditions.elementToBeClickable(By.id("submitBtn"))).click();

Best practice: Use explicit waits for specific elements. Avoid implicit waits (which apply globally) and hard-coded sleeps.

For more on avoiding flaky tests, read Top Test Automation Anti‑Patterns and Ways to Evade Them.

2. Locate Elements Robustly

Locating elements is a core Selenium task. The most common challenge is the StaleElementReferenceException, which occurs when you hold a reference to an element that is no longer in the DOM (e.g., after a page refresh or partial update).

Solutions:

  • Re-query the element: Always re-fetch the element reference before interacting with it.
  • Use Page Object Model (POM): Centralise element locators in page classes, making updates easier.
  • Prefer stable locators: Use data-testid attributes, IDs, or CSS selectors over fragile XPaths.

Example:
Instead of:

java

WebElement button = driver.findElement(By.id("submit"));
button.click(); // May throw StaleElementReferenceException after a refresh

Do:

java

// Re-fetch before each interaction
driver.findElement(By.id("submit")).click();

3. Send Keyboard Input Efficiently

Selenium provides two ways to send input to form fields:

  • sendKeys(): Simulates real keyboard events, triggering JavaScript events.
  • executeScript() (set value property): Directly sets the value attribute without firing events.

When to use each:

  • Use sendKeys() when you need to test real-time validation, character-by-character behaviour, or DOM events.
  • Use executeScript() when you only care about setting the field quickly (e.g., for setup) and are not concerned about events.

Example:

java

// Method 1: SendKeys
driver.findElement(By.id("username")).sendKeys("testuser");

// Method 2: JavaScript
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.getElementById('username').value='testuser';");

4. Execute JavaScript with executeScript vs executeAsyncScript

  • executeScript(): Blocks the next line of code until the script completes.
  • executeAsyncScript(): Does not block the test code; useful for scripts that take time (e.g., waiting for an AJAX response).

Example:

java

// ExecuteScript (synchronous)
js.executeScript("window.scrollTo(0, document.body.scrollHeight);");

// ExecuteAsyncScript (asynchronous)
js.executeAsyncScript(
    "var callback = arguments[arguments.length - 1];" +
    "setTimeout(function(){ callback('done'); }, 3000);"
);

5. Drag & Drop with the Actions API

Use the Actions class for complex interactions like drag and drop, double-click, and hover.

Example:

java

Actions actions = new Actions(driver);
WebElement source = driver.findElement(By.id("source"));
WebElement target = driver.findElement(By.id("target"));
actions.dragAndDrop(source, target).perform();

6. Switching Between Windows and iFrames

  • For iFrames: Use driver.switchTo().frame(frameElement) (by index, name, or WebElement). Return to default content with driver.switchTo().defaultContent().
  • For Windows: Use driver.getWindowHandles() to get all window handles, then driver.switchTo().window(handle).

Example:

java

// Switch to iFrame
driver.switchTo().frame("iframeName");
// Do something in the frame
driver.switchTo().defaultContent(); // Back to main page

// Switch to a new window
String mainWindow = driver.getWindowHandle();
for (String handle : driver.getWindowHandles()) {
    driver.switchTo().window(handle);
}
// Do something in the new window
driver.switchTo().window(mainWindow); // Back to main window

7. Clean Up Properly: Close, Quit, and Dispose

  • driver.close(): Closes the current browser window.
  • driver.quit(): Closes all browser windows and ends the WebDriver session.
  • driver.dispose(): Calls quit() and releases resources (Java-specific).

Best practice: Always call driver.quit() in a finally block or using @After to avoid resource leaks.

For a deeper look at web automation, read How to Conduct Cross-Browser Testing Using Selenium WebDriver.

Part 2: Appium Testing Tips & Tricks (2026)

Appium is the leading tool for mobile app automation. Its cross-platform capabilities make it powerful but also introduce complexity. These tips will help you navigate common Appium challenges.

8. Write Cross-Platform Tests

One of the biggest challenges in mobile testing is managing separate tests for Android and iOS. If your app’s UI elements use consistent accessibility IDs (or content-desc for Android, accessibility-id for iOS), you can share test logic across both platforms.

Key steps:

  • Use accessibility IDs as the primary locator strategy.
  • Ensure the IDs match across Android and iOS.
  • Use platform-specific capabilities (e.g., platformNamedeviceName) to target the right device.
  • Use page objects to abstract platform differences.

Example (WebDriverIO):

javascript

const { remote } = require('webdriverio');

const capabilities = {
    platformName: 'Android', // or 'iOS'
    'appium:deviceName': 'emulator-5554',
    'appium:app': '/path/to/app.apk',
    'appium:automationName': 'UiAutomator2' // or 'XCUITest' for iOS
};

const driver = await remote({
    protocol: 'http',
    hostname: 'localhost',
    port: 4723,
    capabilities: capabilities
});

9. Essential Appium Capabilities

Appium capabilities control how the session is launched. Here are some useful ones to know:

For Android:

CapabilityPurpose
ignoreUnimportantViewsSpeeds up UI Automator scanning.
nativeWebScreenshotTakes screenshots using UI Automator (better than ChromeDriver).
appPackageSpecifies the Android app package name.
appActivitySpecifies the main activity to launch.

For iOS:

CapabilityPurpose
locationServicesAuthorizedPre-authorises location services, avoiding permission alerts.
autoAcceptAlertsAutomatically accepts system alerts (e.g., permission requests).
autoDismissAlertsAutomatically dismisses alerts.
nativeWebTapUses non-JavaScript taps for better reliability.
safariIgnoreFraudWarningBypasses SSL certificate warnings in Safari.
interKeyDelayAdds a delay between keystrokes (useful for apps that can’t keep up).
sendKeyStrategyAvoids the on-screen keyboard entirely.

For All Platforms:

CapabilityPurpose
autoWebviewAutomatically switches to the WebView context for hybrid apps (Cordova/PhoneGap).
newCommandTimeoutSets how long Appium waits for a new command before ending the session.
noResetPrevents the app from being reinstalled or data cleared before each test.
fullResetResets the app data (like noReset but opposite).

For mobile‑specific testing strategies, read Top Mobile Usability Testing Methods Every QA Tester Should Know.

10. Simulate Network Conditions

Appium allows you to simulate different network states using driver.setNetworkConnection().

Example (Java):

java

// 0 = None (Airplane mode)
// 1 = Wi-Fi only
// 2 = Cellular only
// 4 = Data only
// 6 = Wi-Fi and Data (full)
driver.setNetworkConnection(6); // Full connectivity

11. Use the Appium Desktop Inspector

The Appium Desktop Inspector is a powerful tool for viewing the UI hierarchy, identifying element locators, and debugging. It is especially useful for testing complex views and finding stable element attributes.

12. Appium 2.0 and Plugin Architecture

Appium 2.0 introduced a modular plugin architecture. You can now install only the drivers and plugins you need, reducing overhead and improving performance.

Key changes in Appium 2.0:

  • Driver Management: Install drivers separately (e.g., appium driver install uiautomator2).
  • Plugin Support: Extend functionality with plugins (e.g., image comparison, gestures).
  • Simplified Configuration: Easier setup with fewer dependencies.

For a guide to automation frameworks, read Selecting the Right Test Automation Framework: Selenium vs Cypress vs Playwright.

How TestUnity Helps with Appium and Selenium Automation

At TestUnity, we specialise in building and maintaining robust automation frameworks using Selenium and Appium. Our services include:

  • Framework Design: We build scalable, maintainable frameworks following best practices (Page Object Model, data-driven testing).
  • Cross-Platform Test Suites: We design test suites that run seamlessly across web, Android, and iOS.
  • CI/CD Integration: We embed your automation into CI/CD pipelines for continuous validation.
  • Maintenance and Support: We keep your test suites updated as your application evolves.
  • On-Demand Automation Experts: We provide skilled automation engineers to augment your team.

Conclusion

Mastering Selenium and Appium requires more than just learning the basics. By applying these tips and tricks—using explicit waits, robust locators, efficient cleanup, and platform-specific capabilities—you can write more reliable, maintainable, and faster tests.

Key takeaways for 2026:

  • Selenium: Use WebDriverWait, avoid Thread.sleep, handle StaleElementReferenceException, and clean up with quit().
  • Appium: Leverage cross-platform IDs, use appropriate capabilities for Android/iOS, simulate network conditions, and adopt Appium 2.0.
  • General: Combine both tools in a unified automation strategy for full web and mobile coverage.

Ready to optimise your Appium and Selenium automation? Contact TestUnity today to discuss how our automation experts can help you build efficient, maintainable test suites.

Related Resources

  • Best Practices for Selenium Automation Testing – Read more
  • How to Conduct Cross-Browser Testing Using Selenium WebDriver – Read more
  • Selecting the Right Test Automation Framework: Selenium vs Cypress vs Playwright – Read more
  • Top Test Automation Anti‑Patterns and Ways to Evade Them – Read more
  • Complete Guide to Test Automation Services in 2026 – Read more
  • 7 Tips for Developing the Ultimate Test Automation Strategy – Read more

TestUnity is a leading software testing company dedicated to delivering exceptional quality assurance services to businesses worldwide. With a focus on innovation and excellence, we specialize in functional, automation, performance, and cybersecurity testing. Our expertise spans across industries, ensuring your applications are secure, reliable, and user-friendly. At TestUnity, we leverage the latest tools and methodologies, including AI-driven testing and accessibility compliance, to help you achieve seamless software delivery. Partner with us to stay ahead in the dynamic world of technology with tailored QA solutions.

Leave a Reply

Your email address will not be published. Required fields are marked *

Index