program story

WebDriverException : 알 수없는 오류 : Chrome 브라우저를 시작하는 동안 DevToolsActivePort 파일이 존재하지 않습니다.

inputbox 2020. 8. 15. 09:11
반응형

WebDriverException : 알 수없는 오류 : Chrome 브라우저를 시작하는 동안 DevToolsActivePort 파일이 존재하지 않습니다.


URL로 크롬을 시작하려고하는데 브라우저가 시작되고 그 후에는 아무것도하지 않습니다.

1 분 후에 아래 오류가 표시됩니다.

Unable to open browser with url: 'https://www.google.com' (Root cause: org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist
  (Driver info: chromedriver=2.39.562718 (9a2698cba08cf5a471a29d30c8b3e12becabb0e9),platform=Windows NT 10.0.15063 x86_64) (WARNING: The server did not provide any stacktrace information)

내 구성 :

크롬 : 66 크롬 브라우저 : 2.39.56

PS 모든 것이 Firefox에서 잘 작동합니다.


이 오류 메시지 ...

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

... ChromeDriver 가 새 WebBrowser,Chrome 브라우저 세션 을 시작 / 생성 할 수 없음을 나타 냅니다.

귀하의 코드 시험과 모든 바이너리의 버전 관리 정보는 무엇이 잘못되었는지에 대한 힌트를 제공했을 것입니다.

그러나 기본 시작 플래그에 --disable-dev-shm-usage 추가에 따라 인수 --disable-dev-shm-usage추가 하면 일시적으로 문제가 해결되는 것 같습니다 .

Chrome 브라우저 세션 을 시작 / 스팬하려는 경우 다음 솔루션을 사용할 수 있습니다.

System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized"); // open Browser in maximized mode
options.addArguments("disable-infobars"); // disabling infobars
options.addArguments("--disable-extensions"); // disabling extensions
options.addArguments("--disable-gpu"); // applicable to windows os only
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("--no-sandbox"); // Bypass OS security model
WebDriver driver = new ChromeDriver(options);
driver.get("https://google.com");

disable-dev-shm-usage

당으로 base_switches.cc disable-dev-shm-usage 에서만 유효한 것으로 보인다 리눅스 OS :

#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
// The /dev/shm partition is too small in certain VM environments, causing
// Chrome to fail or crash (see http://crbug.com/715363). Use this flag to
// work-around this issue (a temporary directory will always be used to create
// anonymous shared memory files).
const char kDisableDevShmUsage[] = "disable-dev-shm-usage";
#endif

토론 에서 / dev / shm 대신 / tmp를 사용하는 옵션 추가 David는 다음과 같이 언급합니다.

/ dev / shm 및 / tmp 마운트 방법에 따라 달라집니다. 둘 다 tmpfs로 마운트되면 차이가 없다고 가정합니다. 어떤 이유로 / tmp가 tmpfs로 매핑되지 않은 경우 (그리고 systemd에서 기본적으로 tmpfs로 매핑되었다고 생각합니다), Chrome 공유 메모리 관리는 익명 공유 파일을 만들 때 항상 파일을 메모리에 매핑하므로이 경우에도 마찬가지입니다. 많은 차이. 플래그를 활성화 한 상태에서 원격 측정 테스트를 강제하고 어떻게 진행되는지 볼 수 있다고 생각합니다.

기본적으로 사용하지 않는 이유는 공유 메모리 팀에 의해 푸시 백되었으므로 기본적으로 공유 메모리에 / dev / shm을 사용하는 것이 합리적이라고 생각합니다.

궁극적으로이 모든 것이 memfd_create를 사용하도록 이동해야하지만 Chrome 메모리 관리를 크게 리팩토링해야하기 때문에 곧 일어날 것이라고 생각하지 않습니다.


아우트로

다음은 샌드 박스 스토리에 대한 링크 입니다.


나는 월요일 2018-06-04 에이 문제를보기 시작했습니다. 우리의 테스트는 매주 실행됩니다. 변경된 유일한 것은 google-chrome 버전 (현재로 업데이트 됨) JVM과 Selenium이 Linux 박스의 최신 버전 (Java 1.8.0_151, selenium 3.12.0, google-chrome 67.0.3396.62 및 xvfb-run).
특히 " --no-sandbox "및 " --disable-dev-shm-usage " 인수를 추가 하면 오류가 중지되었습니다. 이 문제를 조사하여 효과에 대한 자세한 정보와 google-chrome이 업데이트하도록 트리거 한 기타 질문을 찾을 것입니다.

ChromeOptions options = new ChromeOptions();
        ...
        options.addArguments("--no-sandbox");
        options.addArguments("--disable-dev-shm-usage");

우리는 젠킨스 슬레이브 (리눅스 머신)에서 동일한 문제를 겪었고 위의 모든 옵션을 시도했습니다.

도움이 된 유일한 것은 논쟁을 설정하는 것입니다.

chrome_options.add_argument('--headless')

그러나 우리가 더 조사했을 때 XVFB 화면이 속성을 시작하지 않고이 오류를 일으키는 것으로 나타났습니다. XVFB 화면을 수정 한 후 문제가 해결되었습니다.


나는 파이썬에서 같은 문제가 있었다. 위의 내용이 도움이되었습니다. 다음은 내가 파이썬에서 사용한 것입니다.

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome('/path/to/your_chrome_driver_dir/chromedriver',chrome_options=chrome_options)

최신 정보:

문제를 해결할 수 있으며 이제 원하는 URL로 크롬에 액세스 할 수 있습니다.

제공된 솔루션을 시도한 결과 :

위에 제공된 모든 설정을 시도했지만 문제를 해결할 수 없습니다.

문제에 대한 설명 :

내 관찰에 따라 DevToolsActivePort 파일이 존재하지 않는 것은 크롬이 scoped_dirXXXXX 폴더에서 참조를 찾을 수 없을 때 발생합니다.

문제 해결을 위해 취한 조치

  1. 모든 크롬 프로세스와 크롬 드라이버 프로세스를 종료했습니다.
  2. 크롬을 호출하기 위해 아래 코드를 추가했습니다.

    System.setProperty("webdriver.chrome.driver","pathto\\chromedriver.exe");    
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("useAutomationExtension", false);
    WebDriver driver = new ChromeDriver(options);
    driver.get(url);
    

위의 단계를 사용하여 문제를 해결할 수있었습니다.

답변 해 주셔서 감사합니다.


나는 최근에 같은 문제에 직면했고 시행 착오 끝에 나에게도 효과적이었습니다.

맨 위에 있어야합니다.

options.addArguments("--no-sandbox"); //has to be the very first option

BaseSeleniumTests.java

public abstract class BaseSeleniumTests {

    private static final String CHROMEDRIVER_EXE = "chromedriver.exe";
    private static final String IEDRIVER_EXE = "IEDriverServer.exe";
    private static final String FFDRIVER_EXE = "geckodriver.exe";
    protected WebDriver driver;

    @Before
    public void setUp() {
        loadChromeDriver();
    }

    @After
    public void tearDown() {
        if (driver != null) {
            driver.close();
            driver.quit();
        }
    }

    private void loadChromeDriver() {
        ClassLoader classLoader = getClass().getClassLoader();
        String filePath = classLoader.getResource(CHROMEDRIVER_EXE).getFile();
        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        ChromeDriverService service = new ChromeDriverService.Builder()
                .usingDriverExecutable(new File(filePath))
                .build();
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--no-sandbox"); // Bypass OS security model, MUST BE THE VERY FIRST OPTION
        options.addArguments("--headless");
        options.setExperimentalOption("useAutomationExtension", false);
        options.addArguments("start-maximized"); // open Browser in maximized mode
        options.addArguments("disable-infobars"); // disabling infobars
        options.addArguments("--disable-extensions"); // disabling extensions
        options.addArguments("--disable-gpu"); // applicable to windows os only
        options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
        options.merge(capabilities);
        this.driver = new ChromeDriver(service, options);
    }

}

GoogleSearchPageTraditionalSeleniumTests.java

@RunWith(SpringRunner.class)
@SpringBootTest
public class GoogleSearchPageTraditionalSeleniumTests extends BaseSeleniumTests {

    @Test
    public void getSearchPage() {
        this.driver.get("https://www.google.com");
        WebElement element = this.driver.findElement(By.name("q"));
        assertNotNull(element);
    }

}

pom.xml

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <scope>test</scope>
        </dependency>
</dependencies>

제 경우에는 기본 사용자 프로필을 사용하려고 할 때 발생했습니다.

...
options.addArguments("user-data-dir=D:\\MyHomeDirectory\\Google\\Chrome\\User Data");
...

이로 인해 크롬이 이미 백그라운드에서 실행중인 프로세스를 재사용하도록 트리거하여 chromedriver.exe에 의해 시작된 프로세스가 단순히 종료되었습니다.

해결 방법 : 백그라운드에서 실행중인 모든 chrome.exe 프로세스를 종료합니다.


conf.js의 기능 업데이트

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['todo-spec.js'],
  capabilities: {
    browserName: 'chrome',
    chromeOptions: {
      args: ['--disable-gpu', '--no-sandbox', '--disable-extensions', '--disable-dev-shm-usage']
    }
  },

};

제 경우에는 크롬 브라우저를 사용하여 Windows OS에서 실행 가능한 jar를 만들려고 시도했으며 CentO가있는 유닉스 상자의 헤드리스 모드에서 동일하게 실행하고 싶습니다. 그리고 내 바이너리를 내 제품군과 함께 다운로드하고 패키징 한 드라이버를 가리키고있었습니다. 나 에게이 문제는 아래 추가와 관계없이 계속 발생합니다.

ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--no-sandbox");
System.setProperty("webdriver.chrome.args", "--disable-logging");
System.setProperty("webdriver.chrome.silentOutput", "true");
options.setBinary("/pointing/downloaded/driver/path/in/automationsuite");
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("disable-infobars"); // disabling infobars
options.addArguments("--disable-extensions"); // disabling extensions
options.addArguments("--disable-gpu"); // applicable to windows os only
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("window-size=1024,768"); // Bypass OS security model
options.addArguments("--log-level=3"); // set log level
options.addArguments("--silent");//
options.setCapability("chrome.verbose", false); //disable logging
driver = new ChromeDriver(options);

Solution that I've tried and worked for me is, download the chrome and its tools on the host VM/Unix box, install and point the binary to this in the automation suite and bingo! It works :)

Download command:

wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm

Install command:

sudo yum install -y ./google-chrome-stable_current_*.rpm

Update suite with below binary path of google-chrome:

options.setBinary("/opt/google/chrome/google-chrome");

And.. it works!


As stated in this other answer:

This error message... implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.

Among the possible causes, I would like to mention the fact that, in case you are running an headless Chromium via Xvfb, you might need to export the DISPLAY variable: in my case, I had in place (as recommended) the --disable-dev-shm-usage and --no-sandbox options, everything was running fine, but in a new installation running the latest (at the time of writing) Ubuntu 18.04 this error started to occurr, and the only possible fix was to execute an export DISPLAY=":20" (having previously started Xvfb with Xvfb :20&).


I had the same issue, but in my case chrome previously was installed in user temp folder, after that was reinstalled to Program files. So any of solution provided here was not help me. But if provide path to chrome.exe all works:

chromeOptions.setBinary("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");

I hope this helps someone =)


No solution worked for my. But here is a workaround:

maxcounter=5
for counter in range(maxcounter):
    try:           
        driver = webdriver.Chrome(chrome_options=options,
                          service_log_path=logfile,
                          service_args=["--verbose", "--log-path=%s" % logfile])
        break
    except WebDriverException as e:
        print("RETRYING INITIALIZATION OF WEBDRIVER! Error: %s" % str(e))
        time.sleep(10)
        if counter==maxcounter-1:
            raise WebDriverException("Maximum number of selenium-firefox-webdriver-retries exceeded.")

It seems there are many possible causes for this error. In our case, the error happened because we had the following two lines in code:

System.setProperty("webdriver.chrome.driver", chromeDriverPath);
chromeOptions.setBinary(chromeDriverPath);

It's solved by removing the second line.


I also faced this issue while integrating with jenkins server, I was used the root user for jenkin job, the issue was fixed when I changed the user to other user. I am not sure why this error occurs for the root user.

Google Chrome Version 71.0

ChromeDriver Version 2.45

CentOS7 Version 1.153


I ran into the same issue running Chrome via Behat/Mink and Selenium in a Docker container. After some fiddling, I arrived at the following behat.yml which supplies the switches mentioned above. Note that all of them were required for me to get it running successfully.

default:
    extensions:
        Behat\MinkExtension:
            base_url: https://my.app/
            default_session: selenium2
            selenium2:
                browser: chrome
                capabilities:
                    extra_capabilities:
                        chromeOptions:
                            args:
                                - "headless"
                                - "no-sandbox"
                                - "disable-dev-shm-usage"

In my case, I'm in a Kubernetes environment where I cannot use the default TMPDIR because it will fill up the temp directory with garbage.

So I was using this to use a different tmpdir:

driver = new ChromeDriver(new ChromeDriverService.Builder()
                    .withEnvironment(ImmutableMap.of("TMPDIR", customTmpPath))
                    .build(), options);

But now that I've upgraded everything to the latest, this no longer seems to work. I will need to find a new way to do this.


I solve this problem by installing yum -y install gtk3-devel gtk3-devel-docs", it works ok

My work env is :

Selenium Version 3.12.0
ChromeDriver Version v2.40
Chrome 68 level

Before:
enter image description here enter image description here

After:
enter image description here enter image description here


Since this is the most active message for this type of error, I wanted to mention my solution (after spending hours to fix this).

On Ubuntu 18.04, using Chrome 70 and Chromedriver 2.44, and Python3 I kept getting the same DevToolsActivePort error, even when I disabled all options listed above. The chromedriver log file as well as ps showed that the chromedriver I set in chrome_options.binary_location was running, but it always gave DevToolsActivePort error. When I removed chrome_options.binary_location='....' and add it to webdriver creation, I get it working fine. webdriver.Chrome('/path to ... /chromedriver',chrome_options=chrome_options)

Thanks everybody for your comments that make me understand and resolve the issue.

참고URL : https://stackoverflow.com/questions/50642308/webdriverexception-unknown-error-devtoolsactiveport-file-doesnt-exist-while-t

반응형