Selenium is widely used for browser automation and QA testing. Handling email OTP verification in Selenium tests is notoriously difficult. Here is a clean approach using AgentMailr.

Python + Selenium Example

import httpx
from selenium import webdriver
from selenium.webdriver.common.by import By

API_KEY = "ak_your_key"
BASE = "https://api.agentmailr.com"
HEADERS = {"X-API-Key": API_KEY}

def create_inbox():
    r = httpx.post(f"{BASE}/v1/inboxes", headers=HEADERS, json={})
    return r.json()

def wait_for_otp(inbox_id, timeout=60):
    r = httpx.get(
        f"{BASE}/v1/inboxes/{inbox_id}/otp",
        headers=HEADERS,
        params={"timeout": timeout},
        timeout=timeout + 5
    )
    return r.json()["code"]

# In your test:
inbox = create_inbox()
driver = webdriver.Chrome()
driver.get("https://myapp.com/signup")

driver.find_element(By.NAME, "email").send_keys(inbox["address"])
driver.find_element(By.NAME, "password").send_keys("TestPass123!")
driver.find_element(By.CSS_SELECTOR, "[type=submit]").click()

otp = wait_for_otp(inbox["id"])  # Blocks until OTP arrives
driver.find_element(By.NAME, "otp").send_keys(otp)
driver.find_element(By.CSS_SELECTOR, "button").click()

Java Example

import java.net.http.*;
import java.net.URI;

HttpClient client = HttpClient.newHttpClient();

// Create inbox
HttpRequest create = HttpRequest.newBuilder()
    .uri(URI.create("https://api.agentmailr.com/v1/inboxes"))
    .header("X-API-Key", API_KEY)
    .header("Content-Type", "application/json")
    .POST(HttpRequest.BodyPublishers.ofString("{}"))
    .build();
// Parse response to get inboxId and address...

// Wait for OTP
HttpRequest otp = HttpRequest.newBuilder()
    .uri(URI.create("https://api.agentmailr.com/v1/inboxes/" + inboxId + "/otp?timeout=60"))
    .header("X-API-Key", API_KEY)
    .GET().build();

No IMAP Configuration Needed

The REST API approach works from any language. No IMAP libraries, no OAuth tokens, no email client setup. If your language can make an HTTP request, it can use AgentMailr.