ERROR:child_thread_impl.cc(762)] Request for unkno

2019-09-17 18:13发布

I try to use selenium(latest version, chrome version 58) with org.openqa.selenium.chrome.ChromeDriver. This class has documentation which appears in eclipse. It includes simple test:

import java.io.File;
import java.io.IOException;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.openqa.selenium.By;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

import junit.framework.TestCase;

@RunWith(JUnit4.class)
public class ChromeTest extends TestCase {

    private static ChromeDriverService service;
    private WebDriver driver;

    @BeforeClass
    public static void createAndStartService() {
        service = new ChromeDriverService.Builder()
                .usingDriverExecutable(new File("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"))
                .usingAnyFreePort().build();
        try {
            service.start();
        } catch (IOException e) {
            System.out.println("service didn't start");
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    @AfterClass
    public static void createAndStopService() {
        service.stop();
    }

    @Before
    public void createDriver() {
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.addArguments("--disable-gpu");
        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
        driver = new RemoteWebDriver(service.getUrl(), capabilities);
    }

    @After
    public void quitDriver() {
        driver.quit();
    }

    @Test
    public void testGoogleSearch() {
        driver.get("http://www.google.com");
        WebElement searchBox = driver.findElement(By.name("q"));
        searchBox.sendKeys("webdriver");
        // searchBox.quit();
        assertEquals("webdriver - Google Search", driver.getTitle());
    }
}

When I run it, new google chrome window appears on desktop. And in eclipse console I see:

ERROR:child_thread_impl.cc(762)] Request for unknown Channel-associated interface: ui::mojom::GpuMain

I tried to solve it by using :

ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions.addArguments("--disable-gpu");

But it didn't help. I still have the same error.

After I did debug I see that this error message appears on console when native method java.lang.Thread.start0() is called. Inside java.lang.Thread.start method there is call to native start0().

What is wrong with my comp(windows 7)?

How to solve this ?

Thank you!

1条回答
beautiful°
2楼-- · 2019-09-17 18:38

Solved it.

I misunderstood method usingDriverExecutable of ChromeDriverService.Builder(). This method expects path to chromedriver.exe file but I set path to chrome.exe. Correct code is:

@BeforeClass
    public static void createAndStartService() {
        service = new ChromeDriverService.Builder()
                .usingDriverExecutable(new File("D:\\Downloads\\chromedriver_win32\\chromedriver.exe"))
                .withVerbose(false).usingAnyFreePort().build();
        try {
            service.start();
        } catch (IOException e) {
            System.out.println("service didn't start");
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

You can also set it with webdriver.chrome.driver system property:

System.setProperty("webdriver.chrome.driver", "D:\\Downloads\\chromedriver_win32\\chromedriver.exe");

To download latest chromedriver.exe go to https://sites.google.com/a/chromium.org/chromedriver/downloads. From this page they send you to https://chromedriver.storage.googleapis.com/index.html?path=2.29/.

查看更多
登录 后发表回答