Funcionalidade específica do Edge
Microsoft Edge foi criado com recurso ao Chromium, cuja versão mais antiga suportada é a v79. Tal como o Chrome, a versão (maior) do edgedriver deve ser igual à do navegador Edge.
Todas as capacidades e opções encontradas na página Chrome page irão funcionar de igual forma para o Edge.
Opções
Capabilities common to all browsers are described on the Options page.
Capabilities unique to Chromium are documented at Google’s page for Capabilities & ChromeOptions
Este é um exemplo de como iniciar uma sessão Edge com um conjunto de opções básicas:
EdgeOptions options = new EdgeOptions();
driver = new EdgeDriver(options);
options = webdriver.EdgeOptions()
driver = webdriver.Edge(options=options)
var options = new EdgeOptions();
driver = new EdgeDriver(options);
options = Selenium::WebDriver::Options.edge
@driver = Selenium::WebDriver.for :edge, options: options
.forBrowser(Browser.EDGE)
.setEdgeOptions(options)
.build();
});
Argumentos
The args
parameter is for a list of command line switches to be used when starting the browser.
There are two excellent resources for investigating these arguments:
Opções mais frequentes incluem --start-maximized
e --headless=new
e --user-data-dir=...
Adicione uma opção:
options.addArguments("--start-maximized");
options.add_argument("--start-maximized")
options.AddArgument("--start-maximized");
options.args << '--start-maximized'
.build();
Start browser in a specified location
The binary
parameter takes the path of an alternate location of browser to use. With this parameter you can
use chromedriver to drive various Chromium based browsers.
Add a browser location to options:
options.setBinary(getEdgeLocation());
options.binary_location = edge_bin
options.BinaryLocation = GetEdgeLocation();
options.binary = edge_location
Add extensions
The extensions
parameter accepts crx files. As for unpacked directories,
please use the load-extension
argument instead, as mentioned in
this post.
Add an extension to options:
options.addExtensions(extensionFilePath);
options.add_extension(extension_file_path)
options.AddExtension(extensionFilePath);
options.add_extension(extension_file_path)
.build();
Keeping browser open
Setting the detach
parameter to true will keep the browser open after the process has ended,
so long as the quit command is not sent to the driver.
Note: This is already the default behavior in Java.
options.add_experimental_option("detach", True)
Note: This is already the default behavior in .NET.
options.detach = true
.build();
Excluding arguments
MSEdgedriver has several default arguments it uses to start the browser.
If you do not want those arguments added, pass them into excludeSwitches
.
A common example is to turn the popup blocker back on. A full list of default arguments
can be parsed from the
Chromium Source Code
Set excluded arguments on options:
options.setExperimentalOption("excludeSwitches", List.of("disable-popup-blocking"));
options.add_experimental_option('excludeSwitches', ['disable-popup-blocking'])
options.AddExcludedArgument("disable-popup-blocking");
options.exclude_switches << 'disable-popup-blocking'
});
});
Service
Examples for creating a default Service object, and for setting driver location and port can be found on the Driver Service page.
Log output
Getting driver logs can be helpful for debugging issues. The Service class lets you direct where the logs will go. Logging output is ignored unless the user directs it somewhere.
File output
To change the logging output to save to a specific file:
EdgeDriverService service = new EdgeDriverService.Builder().withLogFile(logLocation).build();
Note: Java also allows setting file output by System Property:
Property key: EdgeDriverService.EDGE_DRIVER_LOG_PROPERTY
Property value: String representing path to log file
service = webdriver.EdgeService(log_output=log_path)
service.LogPath = GetLogLocation();
Console output
To change the logging output to display in the console as STDOUT:
EdgeDriverService service = new EdgeDriverService.Builder().withLogOutput(System.out).build();
Note: Java also allows setting console output by System Property;
Property key: EdgeDriverService.EDGE_DRIVER_LOG_PROPERTY
Property value: DriverService.LOG_STDOUT
or DriverService.LOG_STDERR
$stdout
and $stderr
are both valid values
service.log = $stdout
Log level
There are 6 available log levels: ALL
, DEBUG
, INFO
, WARNING
, SEVERE
, and OFF
.
Note that --verbose
is equivalent to --log-level=ALL
and --silent
is equivalent to --log-level=OFF
,
so this example is just setting the log level generically:
EdgeDriverService service =
new EdgeDriverService.Builder().withLoglevel(ChromiumDriverLogLevel.DEBUG).build();
Note: Java also allows setting log level by System Property:
Property key: EdgeDriverService.EDGE_DRIVER_LOG_LEVEL_PROPERTY
Property value: String representation of ChromiumDriverLogLevel
enum
service = webdriver.EdgeService(service_args=['--log-level=DEBUG'], log_output=log_path)
Log file features
There are 2 features that are only available when logging to a file:
- append log
- readable timestamps
To use them, you need to also explicitly specify the log path and log level. The log output will be managed by the driver, not the process, so minor differences may be seen.
EdgeDriverService service =
new EdgeDriverService.Builder().withAppendLog(true).withReadableTimestamp(true).build();
Note: Java also allows toggling these features by System Property:
Property keys: EdgeDriverService.EDGE_DRIVER_APPEND_LOG_PROPERTY
and EdgeDriverService.EDGE_DRIVER_READABLE_TIMESTAMP
Property value: "true"
or "false"
service = webdriver.EdgeService(service_args=['--append-log', '--readable-timestamp'], log_output=log_path)
service.args << '--append-log'
service.args << '--readable-timestamp'
Disabling build check
Edge browser and msedgedriver versions should match, and if they don’t the driver will error. If you disable the build check, you can force the driver to be used with any version of Edge. Note that this is an unsupported feature, and bugs will not be investigated.
EdgeDriverService service =
new EdgeDriverService.Builder().withBuildCheckDisabled(true).build();
Note: Java also allows disabling build checks by System Property:
Property key: EdgeDriverService.EDGE_DRIVER_DISABLE_BUILD_CHECK
Property value: "true"
or "false"
service = webdriver.EdgeService(service_args=['--disable-build-check'], log_output=log_path)
service.DisableBuildCheck = true;
Modo compatibilidade Internet Explorer
O Microsoft Edge pode ser controlado em modo “compatibilidade Internet Explorer”, são usadas classes do Internet Explorer Driver em conjunção com o Microsoft Edge. Leia a página Internet Explorer para mais detalhes.
Special Features
Some browsers have implemented additional features that are unique to them.
Casting
You can drive Chrome Cast devices with Edge, including sharing tabs
sinks = @driver.cast_sinks
unless sinks.empty?
device_name = sinks.first['name']
@driver.start_cast_tab_mirroring(device_name)
expect { @driver.stop_casting(device_name) }.not_to raise_exception
Network conditions
You can simulate various network conditions.
network_conditions = {
"offline": False,
"latency": 20, # 20 ms of latency
"download_throughput": 2000 * 1024 / 8, # 2000 kbps
"upload_throughput": 2000 * 1024 / 8, # 2000 kbps
}
driver.set_network_conditions(**network_conditions)
@driver.network_conditions = {offline: false, latency: 100, throughput: 200}
Logs
logs = @driver.logs.get(:browser)
Permissions
driver.setPermission("camera", "denied");
driver.set_permissions('camera', 'denied')
@driver.add_permission('camera', 'denied')
@driver.add_permissions('clipboard-read' => 'denied', 'clipboard-write' => 'prompt')
DevTools
See the [Chrome DevTools] section for more information about using DevTools in Edge