Enterprise QA teams often standardize on Java + Selenium. Multilogin exposes a debugger address — attach with Selenium 4 HasCdp or ChromeOptions debuggerAddress after API launch.
Maven deps
<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>4.21.0</version> </dependency>
Launch + attach + cleanup
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.net.URI;
import java.net.http.*;
import java.time.Duration;
public class MlxJob {
static final String MLX = System.getenv("MLX_API");
static final String TOKEN = System.getenv("MLX_TOKEN");
static final HttpClient HTTP = HttpClient.newHttpClient();
static String startProfile(String profileId) throws Exception {
var body = "{\"profile_id\":\"" + profileId + "\",\"headless\":false}";
var req = HttpRequest.newBuilder(URI.create(MLX + "/profile/start"))
.header("Authorization", "Bearer " + TOKEN)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
var resp = HTTP.send(req, HttpResponse.BodyHandlers.ofString());
if (resp.statusCode() >= 400) throw new RuntimeException(resp.body());
// Parse JSON for cdp_url / debuggerAddress — use Jackson/Gson in production
return extractCdpHostPort(resp.body());
}
static void stopProfile(String profileId) throws Exception {
var body = "{\"profile_id\":\"" + profileId + "\"}";
var req = HttpRequest.newBuilder(URI.create(MLX + "/profile/stop"))
.header("Authorization", "Bearer " + TOKEN)
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HTTP.send(req, HttpResponse.BodyHandlers.discarding());
}
public static void main(String[] args) throws Exception {
String profileId = System.getenv("MLX_PROFILE_ID");
String debugger = startProfile(profileId);
WebDriver driver = null;
try {
ChromeOptions opts = new ChromeOptions();
opts.setExperimentalOption("debuggerAddress", debugger);
driver = new RemoteWebDriver(new URI("http://127.0.0.1:4444").toURL(), opts);
driver.get("https://example.com");
new WebDriverWait(driver, Duration.ofSeconds(30))
.until(d -> d.getTitle() != null && !d.getTitle().isEmpty());
System.out.println(driver.getTitle());
} finally {
if (driver != null) driver.quit();
stopProfile(profileId);
}
}
static String extractCdpHostPort(String json) {
// Implement JSON parse — placeholder
throw new UnsupportedOperationException("Parse cdp_url from MLX response");
}
}
In production use Jackson for JSON and externalize retry logic — mirror patterns from API error guide.
Related
Disclosure: MLX-MMO affiliated with Multilogin. Selenium attach API varies by MLX launcher version.