selenium打开浏览器底层实现原理中的异常3.0(org.openqa.selenium.SessionNotCreatedException: Unable to create session)
Posted hadas
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了selenium打开浏览器底层实现原理中的异常3.0(org.openqa.selenium.SessionNotCreatedException: Unable to create session)相关的知识,希望对你有一定的参考价值。
代码:
结果:
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": {
"browserName": "Microsoft
Edge"
},
"capabilities": {
"firstMatch": [
{
"browserName": "Microsoft Edge"
}
]
}
}
Build info: version: ‘3.141.59‘, revision: ‘e82be7d358‘, time: ‘20182be7d358‘, 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.Driver info: driver.versversion: ‘1.8.0_251‘
Driver info: driver.version: unknown
at org.openqa.selenium.remote.server.NewSessionPipeline.lambda$null$4(NewSessionPipeline.java:76)
at java.t org.openqa.selenium.reutil.Optional.orElseThrow(Unknown Source)
at org.openqa.selenium.remote.server.NewSessionPipeline.lambda$createNewSession$5(NewSessionPipeline.java:75)
at java.util.Oper.NewSessionPipeline.crtional.orElseGet(Unknown Source)
at org.openqa.selenium.remote.server.NewSessionPipeline.createNewSession(NewSessionPipeline.java:73)
at org.openqa.selenium.remote.ser.server.WebDriverServletver.commandhandler.BeginSession.execute(BeginSession.java:65)
at org.openqa.selenium.remote.server.WebDriverServlet.lambda$handle$0(WebDriverServlet.java:235)
at java.e)
at java.util.conutil.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWor, ‘stackTrace‘: [{‘fileNker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
‘, ‘stackTrace‘: [{‘fileName‘: ‘NedName‘: ‘orElseThrow‘, ‘wSessionPipeline.java‘, ‘methodName‘: ‘lambda$null$4‘, ‘className‘: ‘org.openqa.selenium.remote.server.NewSessionPipeline‘, ‘lineNumber‘: 76}, {‘fileName‘: None, ‘methodName‘: ‘server.NewSessionPipelinorElseThrow‘, ‘className‘: ‘java.util.Optional‘, ‘lineNumber‘: -1}, {‘fileName‘: ‘NewSessionPipeline.java‘, ‘methodName‘: ‘lambda$createNewSession$5‘, ‘className‘: ‘org.openqa.s‘createNewSession‘, ‘claelenium.remote.server.NewSessionPipeline‘, ‘lineNumber‘: 75}, {‘fileName‘: None, ‘methodName‘: ‘orElseGet‘, ‘className‘: ‘java.util.Optional‘, ‘lineNumber‘: -1}, {‘fileName‘: ‘Nremote.server.commandhanewSessionPipeline.java‘, ‘methodName‘: ‘createNewSession‘, ‘className‘: ‘org.openqa.selenium.remote.server.NewSessionPipeline‘, ‘lineNumber‘: 73}, {‘fileName‘: ‘BeginSession.jav‘lineNumber‘: 235}, {‘fia‘, ‘methodName‘: ‘execute‘, ‘className‘: ‘org.openqa.selenium.remote.server.commandhandler.BeginSession‘, ‘lineNumber‘: 65}, {‘fileName‘: ‘WebDriverServlet.java‘, ‘methodName‘:.util.concurrent.FutureT ‘lambda$handle$0‘, ‘className‘: ‘org.openqa.selenium.remote.server.WebDriverServlet‘, ‘lineNumber‘: 235}, {‘fileName‘: None, ‘methodName‘: ‘call‘, ‘className‘: ‘java.util.concu: ‘run‘, ‘className‘: ‘jrrent.Executors$RunnableAdapter‘, ‘lineNumber‘: -1}, {‘fileName‘: None, ‘methodName‘: ‘run‘, ‘className‘: ‘java.util.concurrent.FutureTask‘, ‘lineNumber‘: -1}, {‘fileName‘: Nonee to create session from, ‘methodName‘: ‘runWorker‘, ‘className‘: ‘java.util.concurrent.ThreadPoolExecutor‘, ‘lineNumber‘: -1}, {‘fileName‘: None, ‘methodName‘: ‘run‘, ‘className‘: ‘java.util.concurren ]
}
}
Build infot.ThreadPoolExecutor$Worker‘, ‘lineNumber‘: -1}, {‘fileName‘: None, ‘methodName‘: ‘run‘, ‘className‘: ‘java.lang.Thread‘, ‘lineNumber‘: -1}], ‘message‘: ‘Unable to create sessio: ‘x86‘, os.version:
from {
"desiredCapabilities": {
"browserName": "Microsoft Edge"
},
"capabilities": {
"firstMatch": [
{
"browserName": "Microsoft Edge"
}
]
}
}
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>
原因分析:
根据日志可以得知从“desiredCapabilities”或者“capabilities”(多重字典)中不能创建session,之所以不能,个中原因可能就是与字典里的值有问题。此时字典里只有一个browserName,所以对于browserName来说就需要考究一下,首先确认了browserName没有写错,然后看一下它的值,对于selenium来说,调取浏览器肯定是要指定浏览器名字的,既然需要指定名字,那么人工入力的名字必须要和selenium内定的一致才行,同时还要区分大小写,否则人家就无法识别。对于设定的‘Microsoft Edge‘,是从Edge浏览器的“关于 Microsoft Edge”看到的,可惜的是在selenium中,正确的写法是"MicrosoftEdge"(没有中间的空格)。由此可知,对于每一个浏览器,selenium都会有指定的名字(key),当用户设定的名字和selenium一致时才可以。
解决方法:
‘browserName‘:‘Microsoft Edge‘ ==》‘browserName‘:‘MicrosoftEdge‘
注意事项:
1.selenium区分大小写
2.指定浏览器名字的时候,必须确认是否是selenium识别的。
3.后工程事项:
3.1.有时间了解一下如何确认自己输入的browserName是否正确。
3.2.有时间整理一下selenium指定主流浏览器的名字是什么的。
以上是关于selenium打开浏览器底层实现原理中的异常3.0(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] 由于目标计算机积 极拒绝,无法连接)