Java Selenium Webdriver有时会启动chrome,但不会加载任何页面

Java Selenium Webdriver有时会启动chrome,但不会加载任何页面,java,ubuntu,selenium,selenium-webdriver,chromium,Java,Ubuntu,Selenium,Selenium Webdriver,Chromium,我使用selenium为一个需要模拟用户交互的研究项目创建了一个网络爬虫。我目前正在使用定制的Chromium二进制文件运行8个单独的webdriver实例(进程) 现在的主要问题是web驱动程序有时会(非决定性地)启动chromium,然后冻结数据;总是打开的页面。i、 它从不导航到我想要的特定URL。你可以看到发生了什么的截图 这发生在大约100个URL被爬网之后。我还没有找到关于StackOverflow的解决方案:(。任何帮助都将不胜感激:D 编辑:另外,我不知道这是否会影响它,但我的

我使用selenium为一个需要模拟用户交互的研究项目创建了一个网络爬虫。我目前正在使用定制的Chromium二进制文件运行8个单独的webdriver实例(进程)

现在的主要问题是web驱动程序有时会(非决定性地)启动chromium,然后冻结数据;总是打开的页面。i、 它从不导航到我想要的特定URL。你可以看到发生了什么的截图

这发生在大约100个URL被爬网之后。我还没有找到关于StackOverflow的解决方案:(。任何帮助都将不胜感激:D

编辑:另外,我不知道这是否会影响它,但我的web驱动程序模拟移动设备。因此,我手动将Chromium窗口的大小设置为移动设备屏幕的大小。我有时会收到下面描述的错误

Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: org.openqa.selenium.WebDriverException: unknown error: Cannot read property 'getCurrent' of undefined
JavaScript stack:
TypeError: Cannot read property 'getCurrent' of undefined
    at updateWindow (chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/background.js:66:17)
    at eval (eval at executeAsyncScript (unknown source), <anonymous>:2:23)
    at executeAsyncScript (<anonymous>:321:26)
    at apply.height (<anonymous>:337:29)
    at callFunction (<anonymous>:229:33)
    at apply.height (<anonymous>:239:23)
    at <anonymous>:240:3
    at Object.InjectedScript._evaluateOn (<anonymous>:878:140)
    at Object.InjectedScript._evaluateAndWrap (<anonymous>:811:34)
    at Object.InjectedScript.evaluate (<anonymous>:667:21)
  (Session info: chrome=49.0.2594.0)
  (Driver info: chromedriver=2.20.353124 (035346203162d32c80f1dce587c8154a1efa0c3b),platform=Linux 3.19.0-25-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 893 milliseconds
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'momalad-virtual-machine', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.19.0-25-generic', java.version: '1.8.0_72-internal'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=true, chrome={userDataDir=/tmp/.com.google.Chrome.ftGDsH}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=true, version=49.0.2594.0, platform=LINUX, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: dbc9347c26adc9507436d38f3c2bbd58
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
    at org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions$RemoteWindow.setSize(RemoteWebDriver.java:891)
    at src.com.chrome.TestChromeDriver.setupPosition(TestChromeDriver.java:160)
    at src.com.chrome.TestChromeDriver.setupDriver(TestChromeDriver.java:155)
    at src.com.chrome.TestChromeDriver.crawl(TestChromeDriver.java:256)
    at src.com.chrome.TestChromeDriver.main(TestChromeDriver.java:113)
    ... 5 more
线程“main”java.lang.reflect.InvocationTargetException中的异常 在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处 位于sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)中 位于java.lang.reflect.Method.invoke(Method.java:498) 位于org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58) 原因:org.openqa.selenium.WebDriverException:未知错误:无法读取未定义的属性“getCurrent” JavaScript堆栈: TypeError:无法读取未定义的属性“getCurrent” 在更新窗口(chrome)-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/background.js:66:17) 在eval(eval at executeAsyncScript(未知源),:2:23) 在executeAsyncScript(:321:26) 在应用高度(:337:29) 在调用函数时(:229:33) 在应用高度(:239:23) 时间:240:3 在Object.InjectedScript._evaluateOn(:878:140) 在Object.InjectedScript.\u evaluateAndWrap(:811:34) 在Object.InjectedScript.evaluate(:667:21) (会话信息:chrome=49.0.2594.0) (驱动程序信息:chromedriver=2.20.353124(035346203162d32c80f1dce587c8154a1efa0c3b),平台=Linux 3.19.0-25-generic x86_64)(警告:服务器未提供任何堆栈跟踪信息) 命令持续时间或超时:893毫秒 生成信息:版本:“未知”,版本:“未知”,时间:“未知” 系统信息:主机:'momalad virtual machine',ip:'127.0.1.1',os.name:'Linux',os.arch:'amd64',os.version:'3.19.0-25-generic',java.version:'1.8.0_72-internal' 驱动程序信息:org.openqa.selenium.chrome.ChromeDriver 功能[{applicationCacheEnabled=false,rotatable=false,mobileEmulationEnabled=true,chrome={userDataDir=/tmp/.com.google.chrome.ftGDsH},takesHeapSnapshot=true,databaseEnabled=false,handlesAlerts=true,hasTouchScreen=true,version=49.0.2594.0,platform=LINUX,browserConnectionEnabled=false,nativeEvents=true,acceptSslCerts=true,locationContextEnabled=true,WebStorage=true,browserName=chrome,takesScreenshot=true,javascriptEnabled=true,CSSSelectorEnabled=true}] 会话ID:dbc9347c26adc9507436d38f3c2bbd58 位于sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法) 位于sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 在sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 位于java.lang.reflect.Constructor.newInstance(Constructor.java:423) 位于org.openqa.selenium.remote.ErrorHandler.CreateTrowable(ErrorHandler.java:206) 位于org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158) 位于org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678) 位于org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions$RemoteWindow.setSize(RemoteWebDriver.java:891) 位于src.com.chrome.TestChromeDriver.setupPosition(TestChromeDriver.java:160) 位于src.com.chrome.TestChromeDriver.setupDriver(TestChromeDriver.java:155) 在src.com.chrome.TestChromeDriver.crawl上(TestChromeDriver.java:256) 位于src.com.chrome.TestChromeDriver.main(TestChromeDriver.java:113) …还有5个 编辑2:为清晰起见,我正在按要求添加我的web驱动程序设置代码:

/**
 * Sets the browser in mobile mode (Nexus 5)
 * Sets the timeout for pages that don't load to 15 seconds
 */
public void initBrowser(){

      // Optional, if not specified, WebDriver will search your path for chromedriver.
      // IF it can't be found, it will needed to be moved to the local directory of this java project
      System.setProperty("webdriver.chrome.driver", "/mnt/crawl/mobmalad/ChromeAdCrawler/Dependencies/chromedriver");

      setupDriver();
}

private void setupDriver(){
    ChromeOptions opts = new ChromeOptions();
    opts.setBinary("/mnt/crawl/mobmalad/ChromeAdCrawler/Dependencies/Release/chrome"); 
    opts.addArguments("--no-sandbox");


    Map<String, String> mobileEmulation = new HashMap<String, String>();
    mobileEmulation.put("deviceName", "Google Nexus 5");

    opts.setExperimentalOption("mobileEmulation", mobileEmulation);


    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability(ChromeOptions.CAPABILITY, opts);


    driver = new ChromeDriver(capabilities);    

    driver.manage().timeouts().pageLoadTimeout(15,TimeUnit.SECONDS);
    driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);


    setupPosition();
}

private void setupPosition(){
    //Determine the desired height and width of the window and store it as a dimension
    int desiredHeight = 728;
    int desiredWidth = 414;   //Half the screen width
    Dimension desiredSize = new Dimension(desiredWidth, desiredHeight);

    //Set the size of the window to the dimension determined above
    driver.manage().window().setSize(desiredSize);

    if(crawlerID<(crawlers/2)){
        driver.manage().window().setPosition(new Point((int) (crawlerID*desiredWidth*.6), 0));
    }else{
        driver.manage().window().setPosition(new Point((int) ((crawlerID-(crawlers/2))*desiredWidth*.6), (int) (desiredHeight)));
    }
}
/**
*将浏览器设置为移动模式(Nexus 5)
*将未加载页面的超时设置为15秒
*/
公共浏览器(){
//可选,如果未指定,WebDriver将在您的路径中搜索chromedriver。
//如果找不到,则需要将其移动到此java项目的本地目录
System.setProperty(“webdriver.chrome.driver”,“/mnt/crawl/mobmalad/chromeadclawler/Dependencies/chromedriver”);
setupDriver();
}
私有void setupDriver(){
ChromeOptions opts=新的ChromeOptions();
opts.setBinary(“/mnt/crawl/mobmalad/chromeadclawler/Dependencies/Release/chrome”);
opts.addArguments(“--no sandbox”);
Map mobileEmulation=new HashMap();
mobileEmulation.put(“deviceName”,“谷歌Nexus5”);
选择设置实验选项(“移动模拟”,移动模拟);
DesiredCapabilities=DesiredCapabilities.chrome();
能力。设置能力(ChromeOptions.CAPABILITY,opts);
驱动程序=新的色度驱动程序(功能);
driver.manage().timeout().pageLoadTimeout(15,TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(1,TimeUnit.SECONDS);
setupPosition();
}
私人职位(){
//确定窗的所需高度和宽度,并将其存储为尺寸标注
int desiredHeight=728;
int desiredWidth=414;//屏幕宽度的一半
尺寸desiredSize=新尺寸(desiredWidth,desiredHeight);
//将窗口大小设置为上面确定的尺寸
driver.manage().window().setSize(desiredSize);

这听起来并不是一个非常可扩展的解决方案。Selenium网格的设计目的是避免创建大型网格