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

Posted hadas

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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.Study30.自动化测试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 {   "desiredCapabilities": {   },   "capabilities": {     "firstMatch": [     ]   } }nBuild info: version: ‘3.141.59‘, revision: ‘e82be7d358‘, time: ‘2018-11-14T08:25:53‘ System 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‘ Driver info: driver.version: unknown at org.openqa.selenium.remote.server.NewSessionPipeline.lambda$null$4(NewSessionPipeline.java:76) at java.util.Optional.orElseThrow(Unknown Source) at org.openqa.selenium.remote.server.NewSessionPipeline.lambda$createNewSession$5(NewSessionPipeline.java:75) at java.util.Optional.orElseGet(Unknown Source) at org.openqa.selenium.remote.server.NewSessionPipeline.createNewSession(NewSessionPipeline.java:73) at org.openqa.selenium.remote.server.commandhandler.BeginSession.execute(BeginSession.java:65) at org.openqa.selenium.remote.server.WebDriverServlet.lambda$handle$0(WebDriverServlet.java:235) at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) ‘, ‘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 {   "desiredCapabilities": {   },   "capabilities": {     "firstMatch": [     ]   } } Build info: version: ‘3.141.59‘, revision: ‘e82be7d358‘, time: ‘2018-11-14T08:25:53‘ System 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‘ Driver info: driver.version: unknown‘, ‘error‘: ‘session not created‘}, ‘status‘: 33}
PS E:30.Study30.自动化测试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‘却是有值的?

 

以上是关于selenium打开浏览器底层实现原理中的异常3.1(org.openqa.selenium.SessionNotCreatedException: Unable to create session)的主要内容,如果未能解决你的问题,请参考以下文章

selenium打开浏览器底层实现原理中的异常1(TypeError: dump() missing 1 required positional argument: 'fp')

selenium打开浏览器底层实现原理中的异常4(Failed to establish a new connection: [WinError 10061] 由于目标计算机积 极拒绝,无法连接)

搞懂webdriver的底层原理,才敢说自己懂自动化!

浅谈python中selenium库调动webdriver驱动浏览器的实现原理

selenium自动化原理

二 selenium原理以及如何操作浏览器