Selenium POM Wrapper
Zero code rewrite. Learn how to wrap your existing, legacy Java and Python Selenium Page Object Models (POMs) into AI-accessible tools.
The Wrapper Concept
You don't have to throw away years of Selenium framework investments. By exposing your high-level Page Object methods (e.g. `loginUser`, `verifyDashboard`) through a lightweight MCP Python/Java wrapper, an AI agent can orchestrate those complex actions without knowing how to write Selenium code.

Step-by-Step Wrapper Implementation
You can expose your existing Selenium Page Object Model suite to AI agents using either the official **TypeScript/Node.js stack** or a standard **Python-based FastMCP stack**. Explore the complete guides for both options below.
⚡ Legacy Framework Note
Because Selenium is a legacy testing engine, there is no official pre-built zero-code MCP server. However, you can run our pre-built TypeScript wrapper (Option A) or Python wrapper (Option B) code with a simple copy-paste to run them in seconds!
Option ATypeScript: Node.js Selenium MCP Setup
Under Node.js, you can build a customized Selenium tool wrapper using the official @modelcontextprotocol/sdk and the native selenium-webdriver library.
Step 1: Install NPM Packages
Initialize a Node project and install the MCP SDK and Selenium drivers:
npm init -y
npm install @modelcontextprotocol/sdk selenium-webdriver
npm install --save-dev typescript @types/node tsx
Step 2: Build the Server
Write a custom script `mcp_selenium_server.ts` to manage WebDriver instances asynchronously:
import{ Server }from"@modelcontextprotocol/sdk/server/index.js";import{ StdioServerTransport }from"@modelcontextprotocol/sdk/server/stdio.js";import{ CallToolRequestSchema, ListToolsRequestSchema }from"@modelcontextprotocol/sdk/types.js";import{ Builder, WebDriver, By }from"selenium-webdriver";letdriver: WebDriver |null=null;constserver =newServer(
{ name:"selenium-mcp-ts", version:"1.0.0"},
{ capabilities: { tools: {} } }
);
// 1. Expose standard Page Object Actions as AI Tools
server.setRequestHandler(ListToolsRequestSchema,async() => {
return{
tools: [
{
name:"execute_selenium_login",
description:"Logs user in using wrapped legacy TS Selenium selectors.",
inputSchema: {
type:"object",
properties: {
username: { type:"string"},
password: { type:"string"}
},
required: ["username","password"]
}
}
]
};
});
// 2. Handle execution of the Selenium tool
server.setRequestHandler(CallToolRequestSchema,async(request) => {
const{ name, arguments: args } = request.params;
if(!driver) {
driver =await newBuilder().forBrowser("chrome").build();
}
if(name ==="execute_selenium_login") {
constusername = args?.usernameasstring;
constpassword = args?.passwordasstring;
awaitdriver.get("https://portal.careerraah.com/login");
awaitdriver.findElement(By.id("username")).sendKeys(username);
awaitdriver.findElement(By.id("password")).sendKeys(password);
awaitdriver.findElement(By.css("button[type='submit']")).click();
consttitle =awaitdriver.getTitle();
return{
content: [{ type:"text", text: `Selenium login action triggered. Current browser title: "${title}"` }]
};
}
throw newError("Tool execution failed.");
});async functionrun() {
consttransport =newStdioServerTransport();
awaitserver.connect(transport);
}
run().catch(console.error);
Option BPython: Legacy Selenium Wrapper Setup
Alternatively, you can build your server using Python's high-level fastmcp framework to wrap your existing Python Selenium POM classes.
Step 1: Install Python Libraries
Install FastMCP and Selenium dependencies:
pip install fastmcp selenium webdriver-manager
Step 2: Build the Server
Write `selenium_mcp_server.py` to wrap legacy Python page object models:
fromfastmcpimportFastMCPfromseleniumimportwebdriver
# Import your existing legacy POMfrompages.login_pageimportLoginPage
server = FastMCP("Legacy-Selenium-Wrapper")
# Keep WebDriver instance alive in global state
driver = webdriver.Chrome()@server.tool()defexecute_login(username:str, password:str) ->str:
"""Logs the user into the portal using legacy Selenium POM."""
login_page = LoginPage(driver)
login_page.navigate_to_login()
login_page.enter_credentials(username, password)
login_page.click_submit()
if"Dashboard"indriver.title:
return"Login successful. Reached dashboard."
else:
return"Login failed."if__name__ =="__main__":
server.run(transport="stdio")
How AI Helps Generate POMs
What if you don't have a POM yet? You can use an agent connected to a pure DOM-reading MCP tool to look at your application, extract stable IDs, and write the Java/Python Selenium Page Object Model class for you.