WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser

前端 未结 29 3365
旧巷少年郎
旧巷少年郎 2020-11-21 07:11

I am trying to launch chrome with an URL, the browser launches and it does nothing after that.

I am seeing the below error after 1 minute:

Unable to         


        
相关标签:
29条回答
  • 2020-11-21 07:16

    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.")
    
    0 讨论(0)
  • 2020-11-21 07:16

    I use chromium but I have created a shell script called chrome just to be easy for me to open the browser from dmenu.

    #!/bin/bash
    
    /usr/bin/chromium
    
    

    Chrome driver looking for chrome in PATH and executes that. In result I got the same error.

    org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited normally.
      (unknown error: DevToolsActivePort file doesn't exist)
      (The process started from chrome location /home/s1n7ax/.local/share/s1n7ax/bin/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
    Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
    System info: host: 's1n7ax', ip: '127.0.1.16', os.name: 'Linux', os.arch: 'amd64', os.version: '5.4.70-1-lts', java.version: '11.0.8'
    Driver info: driver.version: ChromeDriver
    remote stacktrace: #0 0x56030c96dd99 <unknown>
    

    I just removed the shell script and added a soft link to chromium. Everything working now.

    0 讨论(0)
  • 2020-11-21 07:17

    I had the same problem in python. The above helped. Here is what I used in python -

    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)
    
    0 讨论(0)
  • 2020-11-21 07:17

    I was facing the same issue recently and after some trial and error it worked for me as well.

    MUST BE ON TOP:

    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>
    
    0 讨论(0)
  • 2020-11-21 07:18

    We were having the same issues on our jenkins slaves (linux machine) and tried all the options above.

    The only thing helped is setting the argument

    chrome_options.add_argument('--headless')
    

    But when we investigated further, noticed that XVFB screen doesn't started property and thats causing this error. After we fix XVFB screen, it resolved the issue.

    0 讨论(0)
  • 2020-11-21 07:20

    I run selenium tests with Jenkins running on an Ubuntu 18 LTS linux. I had this error until I added the argument 'headless' like this (and some other arguments):

    ChromeOptions options = new ChromeOptions();
    options.addArguments("headless"); // headless -> no browser window. needed for jenkins
    options.addArguments("disable-infobars"); // disabling infobars
    options.addArguments("--disable-extensions"); // disabling extensions
    options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
    options.addArguments("--no-sandbox"); // Bypass OS security model
    ChromeDriver driver = new ChromeDriver(options);
    
    driver.get("www.google.com");
    
    0 讨论(0)
提交回复
热议问题