class RemoteWebDriver implements WebDriver, JavaScriptExecutor, WebDriverHasInputDevices (View source)

Properties

protected HttpCommandExecutor|null $executor
protected WebDriverCapabilities $capabilities
protected string $sessionID
protected RemoteMouse $mouse
protected RemoteKeyboard $keyboard
protected RemoteTouchScreen $touch
protected RemoteExecuteMethod $executeMethod
protected bool $isW3cCompliant

Methods

__construct(HttpCommandExecutor $commandExecutor, string $sessionId, WebDriverCapabilities $capabilities = null, bool $isW3cCompliant = false)

No description

static RemoteWebDriver
create(string $selenium_server_url = 'http://localhost:4444/wd/hub', DesiredCapabilities|array $desired_capabilities = null, int|null $connection_timeout_in_ms = null, int|null $request_timeout_in_ms = null, string|null $http_proxy = null, int|null $http_proxy_port = null, DesiredCapabilities $required_capabilities = null)

Construct the RemoteWebDriver by a desired capabilities.

static RemoteWebDriver
createBySessionID(string $session_id, string $selenium_server_url = 'http://localhost:4444/wd/hub', int|null $connection_timeout_in_ms = null, int|null $request_timeout_in_ms = null)

[Experimental] Construct the RemoteWebDriver by an existing session.

close()

Close the current window.

newWindow() deprecated

Create a new top-level browsing context.

findElement(WebDriverBy $by)

Find the first WebDriverElement using the given mechanism.

findElements(WebDriverBy $by)

Find all WebDriverElements within the current page using the given mechanism.

get(string $url)

Load a new web page in the current browser window.

string
getCurrentURL()

Get a string representing the current URL that the browser is looking at.

string
getPageSource()

Get the source of the last loaded page.

string
getTitle()

Get the title of the current page.

string
getWindowHandle()

Return an opaque handle to this window that uniquely identifies it within this driver instance.

array
getWindowHandles()

Get all window handles available to the current session.

quit()

Quits this driver, closing every associated window.

mixed
executeScript(string $script, array $arguments = [])

Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame.

mixed
executeAsyncScript(string $script, array $arguments = [])

Inject a snippet of JavaScript into the page for asynchronous execution in the context of the currently selected frame.

string
takeScreenshot(string $save_as = null)

Take a screenshot of the current page.

getStatus()

Status returns information about whether a remote end is in a state in which it can create new sessions.

wait(int $timeout_in_second = 30, int $interval_in_millisecond = 250)

Construct a new WebDriverWait by the current WebDriver instance.

manage()

An abstraction for managing stuff you would do in a browser menu. For example, adding and deleting cookies.

navigate()

An abstraction allowing the driver to access the browser's history and to navigate to a given URL.

switchTo()

Switch to a different window or frame.

getMouse()

No description

getKeyboard()

No description

getTouch()

No description

action()

Construct a new action builder.

setCommandExecutor(WebDriverCommandExecutor $executor) deprecated

Set the command executor of this RemoteWebdriver

getCommandExecutor()

Get the command executor of this RemoteWebdriver

setSessionID(string $session_id) deprecated

Set the session id of the RemoteWebDriver.

string
getSessionID()

Get current selenium sessionID

getCapabilities()

Get capabilities of the RemoteWebDriver.

static array
getAllSessions(string $selenium_server_url = 'http://localhost:4444/wd/hub', int $timeout_in_ms = 30000) deprecated

Returns a list of the currently active sessions.

mixed
execute($command_name, array $params = [])

No description

mixed|null
executeCustomCommand(string $endpointUrl, string $method = 'GET', array $params = [])

Execute custom commands on remote end.

bool
isW3cCompliant()

No description

static RemoteWebDriver
createFromResponse(WebDriverResponse $response, HttpCommandExecutor $commandExecutor)

Create instance based on response to NEW_SESSION command.

array
prepareScriptArguments(array $arguments)

Prepare arguments for JavaScript injection

newElement(string $id)

Return the WebDriverElement with the given id.

castToDesiredCapabilitiesObject(array|DesiredCapabilities|null $desired_capabilities = null)

Cast legacy types (array or null) to DesiredCapabilities object. To be removed in future when instance of DesiredCapabilities will be required.

Details

protected __construct(HttpCommandExecutor $commandExecutor, string $sessionId, WebDriverCapabilities $capabilities = null, bool $isW3cCompliant = false)

No description

Parameters

HttpCommandExecutor $commandExecutor
string $sessionId
WebDriverCapabilities $capabilities
bool $isW3cCompliant

false to use the legacy JsonWire protocol, true for the W3C WebDriver spec

static RemoteWebDriver create(string $selenium_server_url = 'http://localhost:4444/wd/hub', DesiredCapabilities|array $desired_capabilities = null, int|null $connection_timeout_in_ms = null, int|null $request_timeout_in_ms = null, string|null $http_proxy = null, int|null $http_proxy_port = null, DesiredCapabilities $required_capabilities = null)

Construct the RemoteWebDriver by a desired capabilities.

Parameters

string $selenium_server_url

The url of the remote Selenium WebDriver server

DesiredCapabilities|array $desired_capabilities

The desired capabilities

int|null $connection_timeout_in_ms

Set timeout for the connect phase to remote Selenium WebDriver server

int|null $request_timeout_in_ms

Set the maximum time of a request to remote Selenium WebDriver server

string|null $http_proxy

The proxy to tunnel requests to the remote Selenium WebDriver through

int|null $http_proxy_port

The proxy port to tunnel requests to the remote Selenium WebDriver through

DesiredCapabilities $required_capabilities

The required capabilities

Return Value

RemoteWebDriver

static RemoteWebDriver createBySessionID(string $session_id, string $selenium_server_url = 'http://localhost:4444/wd/hub', int|null $connection_timeout_in_ms = null, int|null $request_timeout_in_ms = null)

[Experimental] Construct the RemoteWebDriver by an existing session.

This constructor can boost the performance a lot by reusing the same browser for the whole test suite. You cannot pass the desired capabilities because the session was created before.

Parameters

string $session_id

The existing session id

string $selenium_server_url

The url of the remote Selenium WebDriver server

int|null $connection_timeout_in_ms

Set timeout for the connect phase to remote Selenium WebDriver server

int|null $request_timeout_in_ms

Set the maximum time of a request to remote Selenium WebDriver server

Return Value

RemoteWebDriver

WebDriver close()

Close the current window.

Return Value

WebDriver

The current instance.

WebDriver newWindow() deprecated

deprecated Use $driver->switchTo()->newWindow()

Create a new top-level browsing context.

Return Value

WebDriver

The current instance.

WebDriverElement findElement(WebDriverBy $by)

Find the first WebDriverElement using the given mechanism.

Parameters

WebDriverBy $by

Return Value

WebDriverElement

NoSuchElementException is thrown in HttpCommandExecutor if no element is found.

See also

WebDriverBy

WebDriverElement[] findElements(WebDriverBy $by)

Find all WebDriverElements within the current page using the given mechanism.

Parameters

WebDriverBy $by

Return Value

WebDriverElement[]

A list of all WebDriverElements, or an empty array if nothing matches

See also

WebDriverBy

WebDriver get(string $url)

Load a new web page in the current browser window.

Parameters

string $url

Return Value

WebDriver

The current instance.

string getCurrentURL()

Get a string representing the current URL that the browser is looking at.

Return Value

string

The current URL.

string getPageSource()

Get the source of the last loaded page.

Return Value

string

The current page source.

string getTitle()

Get the title of the current page.

Return Value

string

The title of the current page.

string getWindowHandle()

Return an opaque handle to this window that uniquely identifies it within this driver instance.

Return Value

string

The current window handle.

array getWindowHandles()

Get all window handles available to the current session.

Note: Do not use end($driver->getWindowHandles()) to find the last open window, for proper solution see: https://github.com/php-webdriver/php-webdriver/wiki/Alert,-tabs,-frames,-iframes#switch-to-the-new-window

Return Value

array

An array of string containing all available window handles.

quit()

Quits this driver, closing every associated window.

mixed executeScript(string $script, array $arguments = [])

Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame.

The executed script is assumed to be synchronous and the result of evaluating the script will be returned.

Parameters

string $script

The script to inject.

array $arguments

The arguments of the script.

Return Value

mixed

The return value of the script.

mixed executeAsyncScript(string $script, array $arguments = [])

Inject a snippet of JavaScript into the page for asynchronous execution in the context of the currently selected frame.

The driver will pass a callback as the last argument to the snippet, and block until the callback is invoked.

You may need to define script timeout using setScriptTimeout() method of WebDriverTimeouts first.

Parameters

string $script

The script to inject.

array $arguments

The arguments of the script.

Return Value

mixed

The value passed by the script to the callback.

string takeScreenshot(string $save_as = null)

Take a screenshot of the current page.

Parameters

string $save_as

The path of the screenshot to be saved.

Return Value

string

The screenshot in PNG format.

getStatus()

Status returns information about whether a remote end is in a state in which it can create new sessions.

WebDriverWait wait(int $timeout_in_second = 30, int $interval_in_millisecond = 250)

Construct a new WebDriverWait by the current WebDriver instance.

Sample usage:

  $driver->wait(20, 1000)->until(
    WebDriverExpectedCondition::titleIs('WebDriver Page')
  );

Parameters

int $timeout_in_second
int $interval_in_millisecond

Return Value

WebDriverWait

WebDriverOptions manage()

An abstraction for managing stuff you would do in a browser menu. For example, adding and deleting cookies.

Return Value

WebDriverOptions

WebDriverNavigationInterface navigate()

An abstraction allowing the driver to access the browser's history and to navigate to a given URL.

WebDriverTargetLocator switchTo()

Switch to a different window or frame.

WebDriverMouse getMouse()

No description

Return Value

WebDriverMouse

WebDriverKeyboard getKeyboard()

No description

Return Value

WebDriverKeyboard

RemoteTouchScreen getTouch()

No description

Return Value

RemoteTouchScreen

WebDriverActions action()

Construct a new action builder.

Return Value

WebDriverActions

RemoteWebDriver setCommandExecutor(WebDriverCommandExecutor $executor) deprecated

deprecated To be removed in the future. Executor should be passed in the constructor.

internal  
 

Set the command executor of this RemoteWebdriver

Parameters

WebDriverCommandExecutor $executor

Despite the typehint, it have be an instance of HttpCommandExecutor.

Return Value

RemoteWebDriver

HttpCommandExecutor getCommandExecutor()

Get the command executor of this RemoteWebdriver

Return Value

HttpCommandExecutor

RemoteWebDriver setSessionID(string $session_id) deprecated

deprecated To be removed in the future. Session ID should be passed in the constructor.

internal  
 

Set the session id of the RemoteWebDriver.

Parameters

string $session_id

Return Value

RemoteWebDriver

string getSessionID()

Get current selenium sessionID

Return Value

string

WebDriverCapabilities getCapabilities()

Get capabilities of the RemoteWebDriver.

Return Value

WebDriverCapabilities

static array getAllSessions(string $selenium_server_url = 'http://localhost:4444/wd/hub', int $timeout_in_ms = 30000) deprecated

deprecated Removed in W3C WebDriver.

Returns a list of the currently active sessions.

Parameters

string $selenium_server_url

The url of the remote Selenium WebDriver server

int $timeout_in_ms

Return Value

array

mixed execute($command_name, array $params = [])

No description

Parameters

$command_name
array $params

Return Value

mixed

mixed|null executeCustomCommand(string $endpointUrl, string $method = 'GET', array $params = [])

Execute custom commands on remote end.

For example vendor-specific commands or other commands not implemented by php-webdriver.

Parameters

string $endpointUrl
string $method
array $params

Return Value

mixed|null

See also

https://github.com/php-webdriver/php-webdriver/wiki/Custom-commands

bool isW3cCompliant()

internal  
 

No description

Return Value

bool

static protected RemoteWebDriver createFromResponse(WebDriverResponse $response, HttpCommandExecutor $commandExecutor)

internal  
 

Create instance based on response to NEW_SESSION command.

Also detect W3C/OSS dialect and setup the driver/executor accordingly.

Parameters

WebDriverResponse $response
HttpCommandExecutor $commandExecutor

Return Value

RemoteWebDriver

protected array prepareScriptArguments(array $arguments)

Prepare arguments for JavaScript injection

Parameters

array $arguments

Return Value

array

protected RemoteExecuteMethod getExecuteMethod()

No description

Return Value

RemoteExecuteMethod

protected RemoteWebElement newElement(string $id)

Return the WebDriverElement with the given id.

Parameters

string $id

The id of the element to be created.

Return Value

RemoteWebElement

static protected DesiredCapabilities castToDesiredCapabilitiesObject(array|DesiredCapabilities|null $desired_capabilities = null)

Cast legacy types (array or null) to DesiredCapabilities object. To be removed in future when instance of DesiredCapabilities will be required.

Parameters

array|DesiredCapabilities|null $desired_capabilities

Return Value

DesiredCapabilities