Chrome Devtools Protocol with BiDi API
Usage
A seguinte lista de APIs crescerá à medida que o projeto Selenium se prepara para suportar casos de uso do mundo real. Se houver funcionalidades adicionais que você gostaria de ver, por favor, levante uma solicitação de recurso.
As these examples are re-implemented with the WebDriver-Bidi protocol, they will be moved to the WebDriver Bidi pages.
Examples
Basic authentication
Alguns aplicativos fazem o uso da autenticação do navegador para proteger suas páginas. Com o Selenium, você pode automatizar a entrada de credenciais básicas de autenticação sempre que for necessário.
Alternate implementations can be found at CDP Endpoint Basic Authentication and CDP API Basic Authentication
SELENIUM_CI_TOKEN not set
If you want to render content fetched from the GitHub API, please create a
personal access token and set it as an environment variable named SELENIUM_CI_TOKEN. More information about token scopes can
be seen at
available scopes GitHub docs
An alternate implementation may be found at CDP Endpoint Basic Authentication
SELENIUM_CI_TOKEN not set
If you want to render content fetched from the GitHub API, please create a
personal access token and set it as an environment variable named SELENIUM_CI_TOKEN. More information about token scopes can
be seen at
available scopes GitHub docs
SELENIUM_CI_TOKEN not set
If you want to render content fetched from the GitHub API, please create a
personal access token and set it as an environment variable named SELENIUM_CI_TOKEN. More information about token scopes can
be seen at
available scopes GitHub docs
const {Builder} = require('selenium-webdriver');
(async function example() {
try {
let driver = await new Builder()
.forBrowser('chrome')
.build();
const pageCdpConnection = await driver.createCDPConnection('page');
await driver.register('username', 'password', pageCdpConnection);
await driver.get('https://the-internet.herokuapp.com/basic_auth');
await driver.quit();
}catch (e){
console.log(e)
}
}())
val uriPredicate = Predicate { uri: URI ->
uri.host.contains("your-domain.com")
}
(driver as HasAuthentication).register(uriPredicate, UsernameAndPassword.of("admin", "password"))
driver.get("https://your-domain.com/login")
Pin scripts
This can be especially useful when executing on a remote server. For example, whenever you check the visibility of an element, or whenever you use the classic get attribute method, Selenium is sending the contents of a js file to the script execution endpoint. These files are each about 50kB, which adds up.
SELENIUM_CI_TOKEN not set
If you want to render content fetched from the GitHub API, please create a
personal access token and set it as an environment variable named SELENIUM_CI_TOKEN. More information about token scopes can
be seen at
available scopes GitHub docs
SELENIUM_CI_TOKEN not set
If you want to render content fetched from the GitHub API, please create a
personal access token and set it as an environment variable named SELENIUM_CI_TOKEN. More information about token scopes can
be seen at
available scopes GitHub docs
Mutation observation
Mutation Observation(Observação de Mutação) é a capacidade de capturar eventos via WebDriver BiDi quando há mutações DOM em um elemento específico no DOM.
SELENIUM_CI_TOKEN not set
If you want to render content fetched from the GitHub API, please create a
personal access token and set it as an environment variable named SELENIUM_CI_TOKEN. More information about token scopes can
be seen at
available scopes GitHub docs
SELENIUM_CI_TOKEN not set
If you want to render content fetched from the GitHub API, please create a
personal access token and set it as an environment variable named SELENIUM_CI_TOKEN. More information about token scopes can
be seen at
available scopes GitHub docs
SELENIUM_CI_TOKEN not set
If you want to render content fetched from the GitHub API, please create a
personal access token and set it as an environment variable named SELENIUM_CI_TOKEN. More information about token scopes can
be seen at
available scopes GitHub docs
SELENIUM_CI_TOKEN not set
If you want to render content fetched from the GitHub API, please create a
personal access token and set it as an environment variable named SELENIUM_CI_TOKEN. More information about token scopes can
be seen at
available scopes GitHub docs
const {Builder, until} = require('selenium-webdriver');
const assert = require("assert");
(async function example() {
try {
let driver = await new Builder()
.forBrowser('chrome')
.build();
const cdpConnection = await driver.createCDPConnection('page');
await driver.logMutationEvents(cdpConnection, event => {
assert.deepStrictEqual(event['attribute_name'], 'style');
assert.deepStrictEqual(event['current_value'], "");
assert.deepStrictEqual(event['old_value'], "display:none;");
});
await driver.get('dynamic.html');
await driver.findElement({id: 'reveal'}).click();
let revealed = driver.findElement({id: 'revealed'});
await driver.wait(until.elementIsVisible(revealed), 5000);
await driver.quit();
}catch (e){
console.log(e)
}
}())
Console logs and errors
Vigie os eventos console.log e registre os callbacks(retornos de chamada) para processar o evento.
CDP API Console logs and WebDriver BiDi Console logs
Use the WebDriver BiDi Console logs implementation. HasLogEvents
will likely end up deprecated because it does not implement Closeable.
SELENIUM_CI_TOKEN not set
If you want to render content fetched from the GitHub API, please create a
personal access token and set it as an environment variable named SELENIUM_CI_TOKEN. More information about token scopes can
be seen at
available scopes GitHub docs
SELENIUM_CI_TOKEN not set
If you want to render content fetched from the GitHub API, please create a
personal access token and set it as an environment variable named SELENIUM_CI_TOKEN. More information about token scopes can
be seen at
available scopes GitHub docs
SELENIUM_CI_TOKEN not set
If you want to render content fetched from the GitHub API, please create a
personal access token and set it as an environment variable named SELENIUM_CI_TOKEN. More information about token scopes can
be seen at
available scopes GitHub docs
SELENIUM_CI_TOKEN not set
If you want to render content fetched from the GitHub API, please create a
personal access token and set it as an environment variable named SELENIUM_CI_TOKEN. More information about token scopes can
be seen at
available scopes GitHub docs
const {Builder} = require('selenium-webdriver');
(async () => {
try {
let driver = new Builder()
.forBrowser('chrome')
.build();
const cdpConnection = await driver.createCDPConnection('page');
await driver.onLogEvent(cdpConnection, function (event) {
console.log(event['args'][0]['value']);
});
await driver.executeScript('console.log("here")');
await driver.quit();
}catch (e){
console.log(e);
}
})()
fun kotlinConsoleLogExample() {
val driver = ChromeDriver()
val devTools = driver.devTools
devTools.createSession()
val logConsole = { c: ConsoleEvent -> print("Console log message is: " + c.messages)}
devTools.domains.events().addConsoleListener(logConsole)
driver.get("https://www.google.com")
val executor = driver as JavascriptExecutor
executor.executeScript("console.log('Hello World')")
val input = driver.findElement(By.name("q"))
input.sendKeys("Selenium 4")
input.sendKeys(Keys.RETURN)
driver.quit()
}
JavaScript exceptions
Vigie as exceções JS e registre callbacks(retornos de chamada) para processar os detalhes da exceção.
Use the WebDriver BiDi JavaScript exceptions implementation
SELENIUM_CI_TOKEN not set
If you want to render content fetched from the GitHub API, please create a
personal access token and set it as an environment variable named SELENIUM_CI_TOKEN. More information about token scopes can
be seen at
available scopes GitHub docs
SELENIUM_CI_TOKEN not set
If you want to render content fetched from the GitHub API, please create a
personal access token and set it as an environment variable named SELENIUM_CI_TOKEN. More information about token scopes can
be seen at
available scopes GitHub docs
SELENIUM_CI_TOKEN not set
If you want to render content fetched from the GitHub API, please create a
personal access token and set it as an environment variable named SELENIUM_CI_TOKEN. More information about token scopes can
be seen at
available scopes GitHub docs
Interceptação de Rede
Both requests and responses can be recorded or transformed.
Response information
SELENIUM_CI_TOKEN not set
If you want to render content fetched from the GitHub API, please create a
personal access token and set it as an environment variable named SELENIUM_CI_TOKEN. More information about token scopes can
be seen at
available scopes GitHub docs
SELENIUM_CI_TOKEN not set
If you want to render content fetched from the GitHub API, please create a
personal access token and set it as an environment variable named SELENIUM_CI_TOKEN. More information about token scopes can
be seen at
available scopes GitHub docs
SELENIUM_CI_TOKEN not set
If you want to render content fetched from the GitHub API, please create a
personal access token and set it as an environment variable named SELENIUM_CI_TOKEN. More information about token scopes can
be seen at
available scopes GitHub docs
Response transformation
SELENIUM_CI_TOKEN not set
If you want to render content fetched from the GitHub API, please create a
personal access token and set it as an environment variable named SELENIUM_CI_TOKEN. More information about token scopes can
be seen at
available scopes GitHub docs
SELENIUM_CI_TOKEN not set
If you want to render content fetched from the GitHub API, please create a
personal access token and set it as an environment variable named SELENIUM_CI_TOKEN. More information about token scopes can
be seen at
available scopes GitHub docs
SELENIUM_CI_TOKEN not set
If you want to render content fetched from the GitHub API, please create a
personal access token and set it as an environment variable named SELENIUM_CI_TOKEN. More information about token scopes can
be seen at
available scopes GitHub docs
const connection = await driver.createCDPConnection('page')
let url = fileServer.whereIs("/cheese")
let httpResponse = new HttpResponse(url)
httpResponse.addHeaders("Content-Type", "UTF-8")
httpResponse.body = "sausages"
await driver.onIntercept(connection, httpResponse, async function () {
let body = await driver.getPageSource()
assert.strictEqual(body.includes("sausages"), true, `Body contains: ${body}`)
})
driver.get(url)
val driver = ChromeDriver()
val interceptor = new NetworkInterceptor(
driver,
Route.matching(req -> true)
.to(() -> req -> new HttpResponse()
.setStatus(200)
.addHeader("Content-Type", MediaType.HTML_UTF_8.toString())
.setContent(utf8String("Creamy, delicious cheese!"))))
driver.get(appServer.whereIs("/cheese"))
String source = driver.getPageSource()
Request interception
SELENIUM_CI_TOKEN not set
If you want to render content fetched from the GitHub API, please create a
personal access token and set it as an environment variable named SELENIUM_CI_TOKEN. More information about token scopes can
be seen at
available scopes GitHub docs
SELENIUM_CI_TOKEN not set
If you want to render content fetched from the GitHub API, please create a
personal access token and set it as an environment variable named SELENIUM_CI_TOKEN. More information about token scopes can
be seen at
available scopes GitHub docs







