大网数据广告活动
Web 标准与前端开发

New Session

· 52CE 我爱测

The _New Session_ command of the WebDriver API creates a new WebDriver session with the browser. The session identifier returned in the response is required for all subsequent commands.

The New Session command of the WebDriver API creates a new WebDriver session with the browser. The session identifier returned in the response is required for all subsequent commands.

Syntax

Method URI template
POST /session

Payload

  • capabilities
    • : Used to define the features the driver must satisfy when creating a new session. See Capabilities for available options.

Response

The response payload is a JSON object with:

  • sessionId
    • : The unique identifier of the session.
  • capabilities
    • : The negotiated capabilities of the session.

Errors

  • session not created
    • : A new session could not be created.

Examples

Starting a new session

With a WebDriver server running on localhost:4444, the following command starts a new WebDriver session requesting Firefox as the browser:

curl -i -H "Content-Type: application/json" -d '{"capabilities": {"alwaysMatch": {"browserName": "firefox"}}}' http://localhost:4444/session

The output will look similar to the following, where 27c8437e-5e42-43f9-a26f-2db0fd509ec1 is the unique identifier of this session:

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8

{"value":{"sessionId":"27c8437e-5e42-43f9-a26f-2db0fd509ec1","capabilities":{"acceptInsecureCerts":false,"browserName":"firefox","browserVersion":"147.0.4","pageLoadStrategy":"normal","platformName":"mac","proxy":{},"setWindowRect":true,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000}}}}

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。