2
respostas

[Projeto] org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist

Olá,

O selenium não consegue criar uma instancia do chrome.

erro: org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist

classe HelloWordSelenium

package br.com.alura.leilao;

import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class HelloWordSelenium {

    @Test
    public void hello() {
        System.setProperty("webdriver.chrome.driver", "drivers/chromedriver_win32/chromedriver.exe"); // diz onde está o driver
        WebDriver browser = new ChromeDriver();
        browser.navigate().to("http://localhost:8080/leiloes"); // faz a navegação
        browser.quit(); //
    }

}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.1.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>br.com.alura</groupId>
    <artifactId>leilao</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>leilao</name>

    <properties>
        <maven.compiler.version>3.8.1</maven.compiler.version>
        <maven.surefire.version>2.22.1</maven.surefire.version>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-springsecurity5</artifactId>
        </dependency>

        <dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-java8time</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-chrome-driver</artifactId>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

![erro do modal windows:](Insira aqui a descrição dessa imagem para ajudar na acessibilidade )

Alguém sabe como corrigir isso?

2 respostas

Oi Josias!

Aparenta ser algum problema no seu Google Chrome instalado. Sugestão é você desinstalar e instalar novamente o chrome no seu computador ou utilizar o FirefoxDriver:

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-firefox-driver</artifactId>
    <version>4.10.0</version>
</dependency>

https://github.com/mozilla/geckodriver/releases/download/v0.33.0/geckodriver-v0.33.0-win-aarch64.zip

System.setProperty("webdriver.gecko.driver", "drivers/chromedriver_win32/chromedriver.exe"); // diz onde está o driver
WebDriver browser = new FirefoxDriver();

Olá Josias,

Tive esse mesmo problema... O problema é que parece que você esta sem acesso a escrita na pasta padrão do WebDriver (C:\Windows\SystemTemp) Isso pode ocorrer por limitações no seu usuario Windows.

Tente obter acesso de usuario administrador, ou mesmo tentar criar algum arquivo neste diretorio, afim de validar suas permissões.

Att. Raphael Berto