RemoteWebDriver
in package
implements
WebDriver, JavaScriptExecutor, WebDriverHasInputDevices
Table of Contents
Interfaces
- WebDriver
- The interface for WebDriver.
- JavaScriptExecutor
- WebDriver interface implemented by drivers that support JavaScript.
- WebDriverHasInputDevices
- Interface implemented by each driver that allows access to the input devices.
Properties
- $capabilities : WebDriverCapabilities|null
- $executeMethod : RemoteExecuteMethod
- $executor : HttpCommandExecutor|null
- $isW3cCompliant : bool
- $keyboard : RemoteKeyboard
- $mouse : RemoteMouse
- $sessionID : string
- $touch : RemoteTouchScreen
Methods
- action() : WebDriverActions
- Construct a new action builder.
- close() : RemoteWebDriver
- Close the current window.
- create() : static
- Construct the RemoteWebDriver by a desired capabilities.
- createBySessionID() : static
- [Experimental] Construct the RemoteWebDriver by an existing session.
- execute() : mixed
- executeAsyncScript() : mixed
- Inject a snippet of JavaScript into the page for asynchronous execution in the context of the currently selected frame.
- executeCustomCommand() : mixed|null
- Execute custom commands on remote end.
- executeScript() : mixed
- Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame.
- findElement() : RemoteWebElement
- Find the first WebDriverElement using the given mechanism.
- findElements() : array<string|int, RemoteWebElement>
- Find all WebDriverElements within the current page using the given mechanism.
- get() : RemoteWebDriver
- Load a new web page in the current browser window.
- getAllSessions() : array<string|int, mixed>
- Returns a list of the currently active sessions.
- getCapabilities() : WebDriverCapabilities|null
- Get capabilities of the RemoteWebDriver.
- getCommandExecutor() : HttpCommandExecutor
- Get the command executor of this RemoteWebdriver
- getCurrentURL() : string
- Get a string representing the current URL that the browser is looking at.
- getKeyboard() : RemoteKeyboard
- getMouse() : RemoteMouse
- getPageSource() : string
- Get the source of the last loaded page.
- getSessionID() : string
- Get current selenium sessionID
- getStatus() : mixed
- Status returns information about whether a remote end is in a state in which it can create new sessions.
- getTitle() : string
- Get the title of the current page.
- getTouch() : RemoteTouchScreen
- getWindowHandle() : string
- Return an opaque handle to this window that uniquely identifies it within this driver instance.
- getWindowHandles() : array<string|int, mixed>
- Get all window handles available to the current session.
- manage() : WebDriverOptions
- An abstraction for managing stuff you would do in a browser menu. For example, adding and deleting cookies.
- navigate() : WebDriverNavigation
- An abstraction allowing the driver to access the browser's history and to navigate to a given URL.
- newWindow() : WebDriver
- Create a new top-level browsing context.
- quit() : mixed
- Quits this driver, closing every associated window.
- switchTo() : RemoteTargetLocator
- Switch to a different window or frame.
- takeScreenshot() : string
- Take a screenshot of the current page.
- wait() : WebDriverWait
- Construct a new WebDriverWait by the current WebDriver instance.
- __construct() : mixed
- castToDesiredCapabilitiesObject() : DesiredCapabilities
- Cast legacy types (array or null) to DesiredCapabilities object. To be removed in future when instance of DesiredCapabilities will be required.
- getExecuteMethod() : RemoteExecuteMethod
- newElement() : RemoteWebElement
- Return the WebDriverElement with the given id.
- prepareScriptArguments() : array<string|int, mixed>
- Prepare arguments for JavaScript injection
- readExistingCapabilitiesFromSeleniumGrid() : DesiredCapabilities
Properties
$capabilities
protected
WebDriverCapabilities|null
$capabilities
$executeMethod
protected
RemoteExecuteMethod
$executeMethod
$executor
protected
HttpCommandExecutor|null
$executor
$isW3cCompliant
protected
bool
$isW3cCompliant
$keyboard
protected
RemoteKeyboard
$keyboard
$mouse
protected
RemoteMouse
$mouse
$sessionID
protected
string
$sessionID
$touch
protected
RemoteTouchScreen
$touch
Methods
action()
Construct a new action builder.
public
action() : WebDriverActions
Return values
WebDriverActionsclose()
Close the current window.
public
close() : RemoteWebDriver
Return values
RemoteWebDriver —The current instance.
create()
Construct the RemoteWebDriver by a desired capabilities.
public
static create([string $selenium_server_url = 'http://localhost:4444/wd/hub' ][, DesiredCapabilities|array<string|int, mixed> $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 ]) : static
Parameters
- $selenium_server_url : string = 'http://localhost:4444/wd/hub'
-
The url of the remote Selenium WebDriver server
- $desired_capabilities : DesiredCapabilities|array<string|int, mixed> = null
-
The desired capabilities
- $connection_timeout_in_ms : int|null = null
-
Set timeout for the connect phase to remote Selenium WebDriver server
- $request_timeout_in_ms : int|null = null
-
Set the maximum time of a request to remote Selenium WebDriver server
- $http_proxy : string|null = null
-
The proxy to tunnel requests to the remote Selenium WebDriver through
- $http_proxy_port : int|null = null
-
The proxy port to tunnel requests to the remote Selenium WebDriver through
- $required_capabilities : DesiredCapabilities = null
-
The required capabilities
Return values
staticcreateBySessionID()
[Experimental] Construct the RemoteWebDriver by an existing session.
public
static 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 ]) : static
This constructor can boost the performance by reusing the same browser for the whole test suite. On the other hand, because the browser is not pristine, this may lead to flaky and dependent tests. So carefully consider the tradeoffs.
To create the instance, we need to know Capabilities of the previously created session. You can either pass them in $existingCapabilities parameter, or we will attempt to receive them from the Selenium Grid server. However, if Capabilities were not provided and the attempt to get them was not successful, exception will be thrown.
Parameters
- $session_id : string
-
The existing session id
- $selenium_server_url : string = 'http://localhost:4444/wd/hub'
-
The url of the remote Selenium WebDriver server
- $connection_timeout_in_ms : int|null = null
-
Set timeout for the connect phase to remote Selenium WebDriver server
- $request_timeout_in_ms : int|null = null
-
Set the maximum time of a request to remote Selenium WebDriver server
Return values
staticexecute()
public
execute(mixed $command_name[, mixed $params = [] ]) : mixed
Parameters
- $command_name : mixed
- $params : mixed = []
executeAsyncScript()
Inject a snippet of JavaScript into the page for asynchronous execution in the context of the currently selected frame.
public
executeAsyncScript(string $script[, array<string|int, mixed> $arguments = [] ]) : mixed
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
- $script : string
-
The script to inject.
- $arguments : array<string|int, mixed> = []
-
The arguments of the script.
Return values
mixed —The value passed by the script to the callback.
executeCustomCommand()
Execute custom commands on remote end.
public
executeCustomCommand(string $endpointUrl[, string $method = 'GET' ][, array<string|int, mixed> $params = [] ]) : mixed|null
For example vendor-specific commands or other commands not implemented by php-webdriver.
Parameters
- $endpointUrl : string
- $method : string = 'GET'
- $params : array<string|int, mixed> = []
Tags
Return values
mixed|nullexecuteScript()
Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame.
public
executeScript(string $script[, array<string|int, mixed> $arguments = [] ]) : mixed
The executed script is assumed to be synchronous and the result of evaluating the script will be returned.
Parameters
- $script : string
-
The script to inject.
- $arguments : array<string|int, mixed> = []
-
The arguments of the script.
Return values
mixed —The return value of the script.
findElement()
Find the first WebDriverElement using the given mechanism.
public
findElement(WebDriverBy $by) : RemoteWebElement
Parameters
- $by : WebDriverBy
Tags
Return values
RemoteWebElement —NoSuchElementException is thrown in HttpCommandExecutor if no element is found.
findElements()
Find all WebDriverElements within the current page using the given mechanism.
public
findElements(WebDriverBy $by) : array<string|int, RemoteWebElement>
Parameters
- $by : WebDriverBy
Tags
Return values
array<string|int, RemoteWebElement> —A list of all WebDriverElements, or an empty array if nothing matches
get()
Load a new web page in the current browser window.
public
get(string $url) : RemoteWebDriver
Parameters
- $url : string
Return values
RemoteWebDriver —The current instance.
getAllSessions()
Returns a list of the currently active sessions.
public
static getAllSessions([string $selenium_server_url = 'http://localhost:4444/wd/hub' ][, int $timeout_in_ms = 30000 ]) : array<string|int, mixed>
Parameters
- $selenium_server_url : string = 'http://localhost:4444/wd/hub'
-
The url of the remote Selenium WebDriver server
- $timeout_in_ms : int = 30000
Tags
Return values
array<string|int, mixed>getCapabilities()
Get capabilities of the RemoteWebDriver.
public
getCapabilities() : WebDriverCapabilities|null
Return values
WebDriverCapabilities|nullgetCommandExecutor()
Get the command executor of this RemoteWebdriver
public
getCommandExecutor() : HttpCommandExecutor
Return values
HttpCommandExecutorgetCurrentURL()
Get a string representing the current URL that the browser is looking at.
public
getCurrentURL() : string
Return values
string —The current URL.
getKeyboard()
public
getKeyboard() : RemoteKeyboard
Return values
RemoteKeyboardgetMouse()
public
getMouse() : RemoteMouse
Return values
RemoteMousegetPageSource()
Get the source of the last loaded page.
public
getPageSource() : string
Return values
string —The current page source.
getSessionID()
Get current selenium sessionID
public
getSessionID() : string
Return values
stringgetStatus()
Status returns information about whether a remote end is in a state in which it can create new sessions.
public
getStatus() : mixed
getTitle()
Get the title of the current page.
public
getTitle() : string
Return values
string —The title of the current page.
getTouch()
public
getTouch() : RemoteTouchScreen
Return values
RemoteTouchScreengetWindowHandle()
Return an opaque handle to this window that uniquely identifies it within this driver instance.
public
getWindowHandle() : string
Return values
string —The current window handle.
getWindowHandles()
Get all window handles available to the current session.
public
getWindowHandles() : array<string|int, mixed>
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 values
array<string|int, mixed> —An array of string containing all available window handles.
manage()
An abstraction for managing stuff you would do in a browser menu. For example, adding and deleting cookies.
public
manage() : WebDriverOptions
Return values
WebDriverOptionsnavigate()
An abstraction allowing the driver to access the browser's history and to navigate to a given URL.
public
navigate() : WebDriverNavigation
Tags
Return values
WebDriverNavigationnewWindow()
Create a new top-level browsing context.
public
newWindow() : WebDriver
Tags
Return values
WebDriver —The current instance.
quit()
Quits this driver, closing every associated window.
public
quit() : mixed
switchTo()
Switch to a different window or frame.
public
switchTo() : RemoteTargetLocator
Tags
Return values
RemoteTargetLocatortakeScreenshot()
Take a screenshot of the current page.
public
takeScreenshot([string $save_as = null ]) : string
Parameters
- $save_as : string = null
-
The path of the screenshot to be saved.
Return values
string —The screenshot in PNG format.
wait()
Construct a new WebDriverWait by the current WebDriver instance.
public
wait([int $timeout_in_second = 30 ][, int $interval_in_millisecond = 250 ]) : WebDriverWait
Sample usage:
$driver->wait(20, 1000)->until(
WebDriverExpectedCondition::titleIs('WebDriver Page')
);
Parameters
- $timeout_in_second : int = 30
- $interval_in_millisecond : int = 250
Return values
WebDriverWait__construct()
protected
__construct(HttpCommandExecutor $commandExecutor, string $sessionId, WebDriverCapabilities $capabilities[, bool $isW3cCompliant = false ]) : mixed
Parameters
- $commandExecutor : HttpCommandExecutor
- $sessionId : string
- $capabilities : WebDriverCapabilities
- $isW3cCompliant : bool = false
-
false to use the legacy JsonWire protocol, true for the W3C WebDriver spec
castToDesiredCapabilitiesObject()
Cast legacy types (array or null) to DesiredCapabilities object. To be removed in future when instance of DesiredCapabilities will be required.
protected
static castToDesiredCapabilitiesObject([array<string|int, mixed>|DesiredCapabilities|null $desired_capabilities = null ]) : DesiredCapabilities
Parameters
- $desired_capabilities : array<string|int, mixed>|DesiredCapabilities|null = null
Return values
DesiredCapabilitiesgetExecuteMethod()
protected
getExecuteMethod() : RemoteExecuteMethod
Return values
RemoteExecuteMethodnewElement()
Return the WebDriverElement with the given id.
protected
newElement(string $id) : RemoteWebElement
Parameters
- $id : string
-
The id of the element to be created.
Return values
RemoteWebElementprepareScriptArguments()
Prepare arguments for JavaScript injection
protected
prepareScriptArguments(array<string|int, mixed> $arguments) : array<string|int, mixed>
Parameters
- $arguments : array<string|int, mixed>
Return values
array<string|int, mixed>readExistingCapabilitiesFromSeleniumGrid()
protected
static readExistingCapabilitiesFromSeleniumGrid(string $session_id, HttpCommandExecutor $executor) : DesiredCapabilities
Parameters
- $session_id : string
- $executor : HttpCommandExecutor