使用chrome驱动程序为selenium standalone执行get - Exception抛出

时间:2017-05-01 05:46:24

标签: google-chrome selenium selenium-chromedriver

简介

我有selenium独立运行:

curl -XPOST -d'{"capabilities":{"desiredCapabilities":{"browserName":"chrome"}},"desiredCapabilities":{"browserName":"chrome"}}' http://127.0.0.1:4444/wd/hub/session
{"state":null,"sessionId":"d33f687e-62c2-4147-aab1-a1c1bba29aed","hCode":1317400713,"value":{"applicationCacheEnabled":false,"rotatable":false,"networkConnectionEnabled":true,"chrome":{"userDataDir":"/tmp/.com.google.Chrome.w26Qkk"},"takesHeapSnapshot":true,"databaseEnabled":false,"handlesAlerts":true,"hasTouchScreen":true,"version":"57.0.2987.133","platform":"LINUX","browserConnectionEnabled":false,"nativeEvents":true,"acceptSslCerts":true,"webdriver.remote.sessionid":"d33f687e-62c2-4147-aab1-a1c1bba29aed","locationContextEnabled":true,"webStorageEnabled":true,"browserName":"chrome","takesScreenshot":true,"javascriptEnabled":true,"cssSelectorsEnabled":true},"class":"org.openqa.selenium.remote.Response","status":0}

我在同一工作目录中有chromedriver

我创建了chrome会话:

You are using an unsupported command-line flag: -ignore-certificate-errors. Stability and security will suffer.

我看到Chrome已打开并显示消息:

curl -XPOST -d'{"url":"http://stackoverflow.com"}' http://127.0.0.1:4444/wd/hub/session/d33f687e-62c2-4147-aab1-a1c1bba29aed/url

chrome is opened

问题

然后我尝试用chrome打开一个网址:

08:32:33.405 INFO - Executing: [get: http://stackoverflow.com])
08:32:34.255 WARN - Exception thrown
org.openqa.selenium.WebDriverException: unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"5244.1","isDefault":true},"id":1,"name":"","origin":"://"}
  (Session info: chrome=57.0.2987.133)
  (Driver info: chromedriver=2.9.248304,platform=Linux 4.2.0-27-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 64 milliseconds
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'np', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.2.0-27-generic', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, chrome={userDataDir=/tmp/.com.google.Chrome.w26Qkk}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, version=57.0.2987.133, platform=LINUX, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 6d5d29b199469d31ecf04abcfbea2493
    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:215)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:671)
    at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:364)
    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.openqa.selenium.support.events.EventFiringWebDriver$2.invoke(EventFiringWebDriver.java:104)
    at com.sun.proxy.$Proxy4.get(Unknown Source)
    at org.openqa.selenium.support.events.EventFiringWebDriver.get(EventFiringWebDriver.java:163)
    at org.openqa.selenium.remote.server.handler.ChangeUrl.call(ChangeUrl.java:40)
    at org.openqa.selenium.remote.server.handler.ChangeUrl.call(ChangeUrl.java:25)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:176)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
08:32:34.288 WARN - Exception: unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"5244.1","isDefault":true},"id":1,"name":"","origin":"://"}
  (Session info: chrome=57.0.2987.133)
  (Driver info: chromedriver=2.9.248304,platform=Linux 4.2.0-27-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 64 milliseconds
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'np', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.2.0-27-generic', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, chrome={userDataDir=/tmp/.com.google.Chrome.w26Qkk}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, version=57.0.2987.133, platform=LINUX, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 6d5d29b199469d31ecf04abcfbea2493

我得到response

Chrome浏览器会打开网址。

获取URL命令的Selenium独立输出:

curl -XPOST -d'{"capabilities":{"desiredCapabilities":{"browserName":"firefox"}},"desiredCapabilities":{"browserName":"firefox"}}' http://127.0.0.1:4444/wd/hub/session

使用firefox工作

同样的操作适用于firefox和geckodriver:

curl -XPOST -d'{"url":"http://stackoverflow.com"}' http://127.0.0.1:4444/wd/hub/session/73835d43-d566-4e88-bcab-1f45ff4db129/url

google-chrome -version
Google Chrome 57.0.2987.133 

 ./chromedriver -version
Starting ChromeDriver (v2.9.248304) on port 9515

我看到stackoverflow.com在firefox浏览器中打开。

版本

Google Chrome和Chrome驱动程序版本:

        let camera1 = GMSCameraPosition.camera(withLatitude: 45.4654, longitude:9.1859, zoom: 0.0)
        self.mapView = GMSMapView.map(withFrame: cell.mapView.bounds, camera: camera1)

 Alamofire.request(url, method: .post, parameters: nil, encoding: JSONEncoding.default, headers: nil)
        .validate()
        .responseJSON { response in
            switch response.result {
            case .success:
                print(response.result.value!)
                print("Validation Successful")
                let dictResponse = response.result.value as! NSDictionary
                print(dictResponse)
                 let aryRoutes = dictResponse .value(forKey:"routes" ) as! NSArray
                print(aryRoutes)

                var aryOverViewPolyLines :NSArray = []
                aryOverViewPolyLines = aryRoutes .value(forKey: "overview_polyline") as! NSArray
                print(aryOverViewPolyLines)
                let strPoints = (aryOverViewPolyLines.value(forKey: "points") as! NSArray).object(at: 0)
                let polygon = GMSPolygon()
                polygon.path = GMSPath(fromEncodedPath: strPoints as! String)
                print(strPoints)
                let rectangle = GMSPolyline.init(path: polygon.path)
                rectangle.strokeWidth = 2.0
                rectangle.strokeColor = .white
                rectangle.map = self.mapView

                let mapBounds = GMSCoordinateBounds(path: polygon.path!)
                self.mapView.animate(with: GMSCameraUpdate.fit(mapBounds, withPadding: 150.0))



                case .failure(let error):
                print(response.result.value!)
                print(error)
            }
    }

操作系统: Ubuntu 14.04

1 个答案:

答案 0 :(得分:3)

根据您的堆栈跟踪,您使用的是旧的ChromeDriver 2.9 。但是,根据ChromeDriver downloads page,对于Chrome 57,您应该使用ChromeDriver 2.29