Copy-paste WebDriver scripts wired to this hub. Start your server on localhost:8000 first (see how to use this hub).
Selenium 4.6+ ships Selenium Manager, which downloads the right browser driver automatically — no WebDriverManager needed.
<!-- pom.xml -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.25.0</version> <!-- use the latest 4.x -->
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.10.2</version>
<scope>test</scope>
</dependency>python -m venv .venv && source .venv/bin/activate
pip install selenium pytestTargets [data-test='username'], [data-test='password'], [data-test='login-button'] on /swaglabs/index.html.
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.*;
import java.time.Duration;
public class CartPilotLogin {
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
driver.get("http://localhost:8000/swaglabs/index.html");
driver.findElement(By.cssSelector("[data-test='username']")).sendKeys("standard_user");
driver.findElement(By.cssSelector("[data-test='password']")).sendKeys("Pass@123");
driver.findElement(By.cssSelector("[data-test='login-button']")).click();
// inventory items appear only after a successful login
wait.until(ExpectedConditions.visibilityOfElementLocated(
By.cssSelector("[data-test^='item-']")));
System.out.println("Logged in. Products visible.");
driver.quit();
}
}from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
wait = WebDriverWait(driver, 10)
driver.get("http://localhost:8000/swaglabs/index.html")
driver.find_element(By.CSS_SELECTOR, "[data-test='username']").send_keys("standard_user")
driver.find_element(By.CSS_SELECTOR, "[data-test='password']").send_keys("Pass@123")
driver.find_element(By.CSS_SELECTOR, "[data-test='login-button']").click()
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "[data-test^='item-']")))
print("Logged in. Products visible.")
driver.quit()The Testbed → #dynamic-loading. Click [data-test='start'], wait for [data-test='finish'].
driver.get("http://localhost:8000/internet/index.html#dynamic-loading");
driver.findElement(By.cssSelector("[data-test='start']")).click();
WebElement done = wait.until(ExpectedConditions.visibilityOfElementLocated(
By.cssSelector("[data-test='finish']")));
assert done.getText().contains("Hello");CartPilot sort dropdown [data-test='sort'] (log in first).
import org.openqa.selenium.support.ui.Select;
Select sort = new Select(driver.findElement(By.cssSelector("[data-test='sort']")));
sort.selectByValue("hilo"); // price high -> low
// sort.selectByVisibleText("Name (A -> Z)");Demo Elements → #alerts, or The Testbed → #js-alerts.
driver.findElement(By.cssSelector("[data-test='js-confirm']")).click();
Alert a = wait.until(ExpectedConditions.alertIsPresent());
System.out.println(a.getText());
a.accept(); // or a.dismiss(); prompt: a.sendKeys("hi"); a.accept();Demo Elements → #frames. Switch, read, switch back.
driver.switchTo().frame(driver.findElement(By.cssSelector("[data-test='frame1']")));
String heading = driver.findElement(By.cssSelector("[data-test='frame-heading']")).getText();
driver.switchTo().defaultContent();Demo Elements → #windows.
String original = driver.getWindowHandle();
driver.findElement(By.cssSelector("[data-test='new-tab']")).click();
wait.until(d -> d.getWindowHandles().size() > 1);
for (String h : driver.getWindowHandles())
if (!h.equals(original)) driver.switchTo().window(h);
System.out.println("Popup title: " + driver.getTitle());
driver.close();
driver.switchTo().window(original);Demo Elements → #droppable.
import org.openqa.selenium.interactions.Actions;
driver.get("http://localhost:8000/elements/index.html#droppable");
WebElement src = driver.findElement(By.cssSelector("[data-test='drag-me']"));
WebElement dst = driver.findElement(By.cssSelector("[data-test='drop-here']"));
new Actions(driver).dragAndDrop(src, dst).perform();
// double click / right click also live on Actions:
// new Actions(driver).doubleClick(el).perform();
// new Actions(driver).contextClick(el).perform();Thread.sleep. Use WebDriverWait + ExpectedConditions (or a FluentWait). The Testbed's Wait Scenarios and Dynamic Controls fire after a random 1–4s, so a fixed sleep will flake — that's the point.| [data-test='username'] | CartPilot login username |
| [data-test='login-button'] | CartPilot login submit |
| [data-test^='item-'] | CartPilot inventory cards (post-login) |
| [data-test='start'] / ['finish'] | Testbed dynamic loading |
| [data-test='sort'] | CartPilot sort dropdown |
| [data-test='js-confirm'] | Confirm dialog trigger |
| [data-test='frame1'] / ['frame-heading'] | Demo Elements frame + inner heading |
| [data-test='new-tab'] | Demo Elements open-tab button |
| [data-test='drag-me'] / ['drop-here'] | Demo Elements droppable |