• chrome 和 chromeDriver


    在写selenium的时候,发现很简单的case也报错

    package com.lv.test;
    
    import org.junit.Test;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    
    public class Orders {
    	
    	private WebDriver driver = new ChromeDriver();
    	String orderUrl="http://www.baidu.com";
    	
    	@Test
    	public void OrdersPage(){
    		driver.get(orderUrl);
    		System.out.println(driver.getTitle());	
    		driver.quit();
    	}
    }

      

    org.openqa.selenium.WebDriverException: unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"15372.1","isDefault":true},"id":1,"name":"","origin":"://"}
      (Session info: chrome=57.0.2987.110)
      (Driver info: chromedriver=2.7.236900,platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 184 milliseconds
    Build info: version: '2.26.0', revision: '18041', time: '2012-11-01 19:33:38'
    System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_20'
    Driver info: driver.version: RemoteWebDriver
    Session ID: 0db0541b1e8337218da90c01bd25804b
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:188)
        at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:531)
        at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:275)
        at com.lvmama.test.Orders.OrdersPage(Orders.java:20)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
     
    百度后知道这是由于Chrome和chromeDriver的不匹配造成的
    然后就查Chrome和chromeDriver的对应关系:
    可以在这里http://chromedriver.storage.googleapis.com/index.html,点击其中某个Chrome版本进入到下载页面(我选择的是2.30)
    在下载页面有个notes.txt文件,点击这个文件就能看到这个ChromeDriver支持的Chrome版本了
    然后下载下来的是一个压缩包,解压其中的.exe文件后,放到Chrome的安装目录下
    我的安装目录是:C:Program Files (x86)GoogleChromeApplication
    如果你是直接复制替换文件,可能会提醒文件被占用的什么东西,可能是刚才你跑selenium的时候没有写diriver.quit()
    (哎,这坑我都能踩,也是醉了,所以说不管写多简单的case都要最后quit一下,别图省事),只需要打开任务管理器,结束chromedriver.exe就好
     
     
     
    升级Chrome以后执行case报错,所以,切忌不要乱升级chrome浏览器
    如何看chromedriver的版本呢?MacOS下直接输入【chromedriver】命令回车就行
    $ chromedriver 
    Starting ChromeDriver 85.0.4183.38 (9047dbc2c693f044042bbec5c91401c708c7c26a-refs/branch-heads/4183@{#779}) on port 9515
    Only local connections are allowed.
    Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
    ChromeDriver was started successfully.
    

     然后在看看chrome的版本

    然后就要重新下载86版本的chromedirver了,有条件的读者可以直接到官网下载:

    https://chromedriver.chromium.org/downloads

    或者在这里下载也行:http://chromedriver.storage.googleapis.com/index.html

     
  • 相关阅读:
    枚举扩展,感觉用处很大
    基础缓存操作类
    ASP.NET 4.0 全局取消表单危险字符验证
    拦截所有经过IOC的方法
    关于使用EPPlus插入列,名称管理器公式失效问题案列分析
    IocFactory容器实体
    线程扩展
    IEnumerable扩展支持Add,Remove等操作
    自定义特性。配合枚举使用棒棒哒
    在数据仓储的情况下进一步封装数据库基础操作,此版本为异步版本
  • 原文地址:https://www.cnblogs.com/lybolg/p/7112766.html
Copyright © 2020-2023  润新知