selenium打开浏览器底层实现原理中的异常3.1(org.openqa.selenium.SessionNotCreatedException: Unable to create session)

代码:

#coding=utf-8
import requests
import json
url='http://127.0.0.1:4444/wd/hub/session'
data = json.dumps({
    'capabilities':{
        'browserName':'MicrosoftEdge'
    }
})
print(requests.post(url,data).json())

结果:

PS E:\30.Study\30.自动化测试\99.零基础入门 Python Web 自动化测试\10.seleniumCodePractice> & "C:/Program Files/Python38/python.exe" "e:/30.Study/30.自动化测试/99.零基础入门 Python Web 自动化测试/10.seleniumCodePractice/202006/requests_open_browser.py"
{'value': {'stacktrace': 'org.openqa.selenium.SessionNotCreatedException: Unable to create session from {\n  "desiredCapabilities": {\n  },\n  "capabilities": {\n    "firstMatch": [\n    ]\n  }\n}\nBuild info: version: \'3.141.59\', revision: \'e82be7d358\', time: \'2018-11-14T08:25:53\'\nSystem info: host: \'DESKTOP-14VQUSG\', ip: \'192.168.137.1\', os.name: \'Windows 10\', os.arch: \'x86\', os.version: \'10.0\', java.version: \'1.8.0_251\'\nDriver info: driver.version: unknown\r\n\tat org.openqa.selenium.remote.server.NewSessionPipeline.lambda$null$4(NewSessionPipeline.java:76)\r\n\tat java.util.Optional.orElseThrow(Unknown Source)\r\n\tat org.openqa.selenium.remote.server.NewSessionPipeline.lambda$createNewSession$5(NewSessionPipeline.java:75)\r\n\tat java.util.Optional.orElseGet(Unknown Source)\r\n\tat org.openqa.selenium.remote.server.NewSessionPipeline.createNewSession(NewSessionPipeline.java:73)\r\n\tat org.openqa.selenium.remote.server.commandhandler.BeginSession.execute(BeginSession.java:65)\r\n\tat org.openqa.selenium.remote.server.WebDriverServlet.lambda$handle$0(WebDriverServlet.java:235)\r\n\tat java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)\r\n\tat java.util.concurrent.FutureTask.run(Unknown Source)\r\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)\r\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)\r\n\tat java.lang.Thread.run(Unknown Source)\r\n', 'stackTrace': [{'fileName': 'NewSessionPipeline.java', 'methodName': 'lambda$null$4', 'className': 'org.openqa.selenium.remote.server.NewSessionPipeline', 'lineNumber': 76}, {'fileName': None, 'methodName': 'orElseThrow', 'className': 'java.util.Optional', 'lineNumber': -1}, {'fileName': 'NewSessionPipeline.java',
'methodName': 'lambda$createNewSession$5', 'className': 'org.openqa.selenium.remote.server.NewSessionPipeline', 'lineNumber': 75}, {'fileName': None, 'methodName': 'orElseGet',
'className': 'java.util.Optional', 'lineNumber': -1}, {'fileName': 'NewSessionPipeline.java', 'methodName': 'createNewSession', 'className': 'org.openqa.selenium.remote.server.NewSessionPipeline', 'lineNumber': 73}, {'fileName': 'BeginSession.java', 'methodName': 'execute', 'className': 'org.openqa.selenium.remote.server.commandhandler.BeginSession', 'lineNumber': 65}, {'fileName': 'WebDriverServlet.java', 'methodName': 'lambda$handle$0', 'className': 'org.openqa.selenium.remote.server.WebDriverServlet', 'lineNumber': 235}, {'fileName': None, 'methodName': 'call', 'className': 'java.util.concurrent.Executors$RunnableAdapter', 'lineNumber': -1}, {'fileName': None, 'methodName': 'run', 'className': 'java.util.concurrent.FutureTask', 'lineNumber': -1}, {'fileName': None, 'methodName': 'runWorker', 'className': 'java.util.concurrent.ThreadPoolExecutor', 'lineNumber': -1}, {'fileName': None, 'methodName': 'run', 'className': 'java.util.concurrent.ThreadPoolExecutor$Worker', 'lineNumber': -1}, {'fileName': None, 'methodName': 'run', 'className': 'java.lang.Thread', 'lineNumber': -1}], 'message': 'Unable to create session from {\n  "desiredCapabilities": {\n  },\n  "capabilities": {\n    "firstMatch": [\n    ]\n  }\n}\nBuild info: version: \'3.141.59\', revision: \'e82be7d358\', time: \'2018-11-14T08:25:53\'\nSystem info: host: \'DESKTOP-14VQUSG\', ip: \'192.168.137.1\', os.name: \'Windows 10\', os.arch: \'x86\', os.version: \'10.0\', java.version: \'1.8.0_251\'\nDriver info: driver.version: unknown', 'error': 'session not created'}, 'status': 33}
PS E:\30.Study\30.自动化测试\99.零基础入门 Python Web 自动化测试\10.seleniumCodePractice>

原因分析:

结合【selenium打开浏览器底层实现原理中的异常3.0(org.openqa.selenium.SessionNotCreatedException: Unable to create session) 】的“原因分析”,是字典里的值有问题。在这里desiredCapabilities之所以是空的,是因为在代码里调用的是“capabilities”,所以此时desiredCapabilities就成空的了。

对应方法:

'capabilities' ==> 'desiredCapabilities'

 

思考:

1.为什么调用'capabilities'的时候'desiredCapabilities'是空的?

2.为什么调用'desiredCapabilities'的时候'capabilities'却是有值的?

 

posted on 2020-06-18 23:42  shiberhou  阅读(1770)  评论(0编辑  收藏  举报

导航