or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

capabilities-management.mdcommand-execution.mddistributed-tracing.mddriver-services.mdhttp-communication.mdindex.mdwebdriver-operations.md

webdriver-operations.mddocs/

0

# WebDriver Operations

1

2

Core WebDriver implementation providing the primary interface for remote browser control, including navigation, element interaction, JavaScript execution, and session management.

3

4

## Capabilities

5

6

### RemoteWebDriver

7

8

The main WebDriver implementation for controlling remote browser instances.

9

10

```java { .api }

11

/**

12

* Remote WebDriver implementation that communicates with browser instances via HTTP

13

*/

14

@Augmentable

15

public class RemoteWebDriver implements WebDriver, HasCapabilities, TakesScreenshot,

16

JavascriptExecutor, PrintsPage, Interactive, HasDownloads, HasVirtualAuthenticator,

17

HasFederatedCredentialManagement {

18

19

// Constructors

20

public RemoteWebDriver();

21

public RemoteWebDriver(Capabilities capabilities);

22

public RemoteWebDriver(Capabilities capabilities, boolean enableTracing);

23

public RemoteWebDriver(URL remoteAddress, Capabilities capabilities);

24

public RemoteWebDriver(URL remoteAddress, Capabilities capabilities, boolean enableTracing);

25

public RemoteWebDriver(CommandExecutor executor, Capabilities capabilities);

26

27

// Navigation

28

public void get(String url);

29

public String getCurrentUrl();

30

public String getTitle();

31

public String getPageSource();

32

public void close();

33

public void quit();

34

35

// Window management

36

public Set<String> getWindowHandles();

37

public String getWindowHandle();

38

public TargetLocator switchTo();

39

public Navigation navigate();

40

public Options manage();

41

42

// Element operations

43

public WebElement findElement(By locator);

44

public List<WebElement> findElements(By locator);

45

46

// JavaScript execution

47

public Object executeScript(String script, Object... args);

48

public Object executeAsyncScript(String script, Object... args);

49

50

// Screenshots

51

public <X> X getScreenshotAs(OutputType<X> outputType) throws WebDriverException;

52

53

// PDF generation

54

public Pdf print(PrintOptions printOptions);

55

56

// Session information

57

public Capabilities getCapabilities();

58

public SessionId getSessionId();

59

public void setLogLevel(Level level);

60

61

// File handling

62

public FileDetector getFileDetector();

63

public void setFileDetector(FileDetector detector);

64

65

// Downloads management

66

public List<String> getDownloadableFiles();

67

public void downloadFile(String fileName, Path targetLocation) throws IOException;

68

public void deleteDownloadableFiles();

69

70

// Script management

71

public Script script();

72

73

// Network management

74

public Network network();

75

76

// Virtual Authenticator support

77

public VirtualAuthenticator addVirtualAuthenticator(VirtualAuthenticatorOptions options);

78

public void removeVirtualAuthenticator(VirtualAuthenticator authenticator);

79

80

// FedCM support

81

public FederatedCredentialManagementDialog getFederatedCredentialManagementDialog();

82

public void setDelayEnabled(boolean enabled);

83

public void resetCooldown();

84

85

// Builder pattern (Beta)

86

public static RemoteWebDriverBuilder builder();

87

}

88

```

89

90

**Usage Examples:**

91

92

```java

93

import org.openqa.selenium.remote.RemoteWebDriver;

94

import org.openqa.selenium.remote.DesiredCapabilities;

95

import org.openqa.selenium.By;

96

import org.openqa.selenium.WebElement;

97

import java.net.URL;

98

99

// Basic setup

100

DesiredCapabilities caps = new DesiredCapabilities();

101

caps.setBrowserName("chrome");

102

RemoteWebDriver driver = new RemoteWebDriver(

103

new URL("http://localhost:4444/wd/hub"), caps);

104

105

// Navigation

106

driver.get("https://example.com");

107

String title = driver.getTitle();

108

String currentUrl = driver.getCurrentUrl();

109

110

// Element interaction

111

WebElement element = driver.findElement(By.id("submit-button"));

112

element.click();

113

114

// JavaScript execution

115

Object result = driver.executeScript("return document.title;");

116

Long count = (Long) driver.executeScript("return arguments[0].length;", "hello");

117

118

// Window management

119

String originalWindow = driver.getWindowHandle();

120

Set<String> allWindows = driver.getWindowHandles();

121

122

// Cleanup

123

driver.quit();

124

```

125

126

### RemoteWebDriverBuilder

127

128

Builder pattern for creating RemoteWebDriver instances with flexible configuration (Beta feature).

129

130

```java { .api }

131

/**

132

* Builder for creating RemoteWebDriver instances with flexible configuration

133

*/

134

public class RemoteWebDriverBuilder {

135

public RemoteWebDriverBuilder addAlternative(Capabilities capabilities);

136

public RemoteWebDriverBuilder addMetadata(String key, Object value);

137

public RemoteWebDriverBuilder setCapability(String key, Object value);

138

public RemoteWebDriverBuilder address(URI uri);

139

public RemoteWebDriverBuilder withDriverService(DriverService service);

140

public RemoteWebDriver build();

141

}

142

```

143

144

**Usage Examples:**

145

146

```java

147

import org.openqa.selenium.remote.RemoteWebDriver;

148

import org.openqa.selenium.chrome.ChromeOptions;

149

import java.net.URI;

150

151

// Using builder pattern

152

RemoteWebDriver driver = RemoteWebDriver.builder()

153

.address(URI.create("http://localhost:4444/wd/hub"))

154

.addAlternative(new ChromeOptions())

155

.addMetadata("test-name", "my-test")

156

.setCapability("browserVersion", "latest")

157

.build();

158

```

159

160

### RemoteWebElement

161

162

WebElement implementation for remote elements that provides all standard element interaction capabilities.

163

164

```java { .api }

165

/**

166

* WebElement implementation for elements controlled through remote WebDriver

167

*/

168

public class RemoteWebElement implements WebElement, TakesScreenshot,

169

Locatable, WrapsDriver {

170

171

// Element actions

172

public void click();

173

public void submit();

174

public void sendKeys(CharSequence... keysToSend);

175

public void clear();

176

177

// Element properties

178

public String getTagName();

179

public String getDomProperty(String name);

180

public String getDomAttribute(String name);

181

public String getAttribute(String name);

182

public String getAriaRole();

183

public String getAccessibleName();

184

public String getText();

185

public String getCssValue(String propertyName);

186

187

// Element state

188

public boolean isSelected();

189

public boolean isEnabled();

190

public boolean isDisplayed();

191

192

// Element location and size

193

public Point getLocation();

194

public Dimension getSize();

195

public Rectangle getRect();

196

197

// Element search

198

public WebElement findElement(By locator);

199

public List<WebElement> findElements(By locator);

200

public SearchContext getShadowRoot();

201

202

// Screenshots (Beta)

203

public <X> X getScreenshotAs(OutputType<X> outputType) throws WebDriverException;

204

205

// Internal methods

206

public String getId();

207

public void setId(String id);

208

public void setParent(RemoteWebDriver parent);

209

public void setFileDetector(FileDetector detector);

210

public Map<String, Object> toJson();

211

}

212

```

213

214

**Usage Examples:**

215

216

```java

217

import org.openqa.selenium.By;

218

import org.openqa.selenium.WebElement;

219

import org.openqa.selenium.remote.RemoteWebElement;

220

221

// Element interaction

222

WebElement input = driver.findElement(By.name("username"));

223

input.sendKeys("testuser");

224

input.clear();

225

226

// Element properties

227

String tagName = input.getTagName();

228

String value = input.getAttribute("value");

229

String cssColor = input.getCssValue("color");

230

boolean isEnabled = input.isEnabled();

231

232

// Element location

233

Point location = input.getLocation();

234

Dimension size = input.getSize();

235

Rectangle rect = input.getRect();

236

237

// Nested element search

238

WebElement form = driver.findElement(By.id("login-form"));

239

WebElement submitButton = form.findElement(By.tagName("button"));

240

241

// Shadow DOM access

242

SearchContext shadowRoot = element.getShadowRoot();

243

WebElement shadowElement = shadowRoot.findElement(By.cssSelector("input"));

244

```

245

246

### File Detection

247

248

File detection system for handling file uploads in remote environments.

249

250

```java { .api }

251

/**

252

* Interface for detecting local files during remote operations

253

*/

254

public interface FileDetector {

255

File getLocalFile(CharSequence... keys);

256

}

257

258

/**

259

* File detector that identifies local files for upload

260

*/

261

public class LocalFileDetector implements FileDetector {

262

public LocalFileDetector();

263

public File getLocalFile(CharSequence... keys);

264

}

265

266

/**

267

* No-op file detector (default behavior)

268

*/

269

public class UselessFileDetector implements FileDetector {

270

public UselessFileDetector();

271

public File getLocalFile(CharSequence... keys);

272

}

273

```

274

275

**Usage Examples:**

276

277

```java

278

import org.openqa.selenium.remote.LocalFileDetector;

279

import org.openqa.selenium.By;

280

import org.openqa.selenium.WebElement;

281

282

// Enable file detection for uploads

283

driver.setFileDetector(new LocalFileDetector());

284

285

// Upload a file

286

WebElement fileInput = driver.findElement(By.type("file"));

287

fileInput.sendKeys("/path/to/local/file.txt");

288

```

289

290

### Script Management

291

292

Script management functionality for pinning and executing JavaScript code efficiently.

293

294

```java { .api }

295

/**

296

* Interface for managing pinned scripts

297

*/

298

public interface Script {

299

ScriptKey pin(String script);

300

void unpin(ScriptKey key);

301

Set<ScriptKey> getPinnedScripts();

302

Object executeScript(ScriptKey key, Object... args);

303

}

304

```

305

306

**Usage Examples:**

307

308

```java

309

// Pin a frequently used script

310

Script scriptManager = driver.script();

311

ScriptKey key = scriptManager.pin("return document.readyState;");

312

313

// Execute pinned script multiple times efficiently

314

Object state1 = scriptManager.executeScript(key);

315

Object state2 = scriptManager.executeScript(key);

316

317

// Clean up

318

scriptManager.unpin(key);

319

```

320

321

### Network Management

322

323

Network-level operations including authentication handlers.

324

325

```java { .api }

326

/**

327

* Interface for network-related operations

328

*/

329

public interface Network {

330

void addAuthenticationHandler(Predicate<URI> when, Supplier<Credentials> authentication);

331

void clearAuthenticationHandlers();

332

}

333

```