selenium打开浏览器底层实现原理中的异常3.0(org.openqa.selenium.SessionNotCreatedException: Unable to create session)
代码:
结果:
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 "browserName": "Microsoft
Edge"\n },\n "capabilities": {\n "firstMatch": [\n {\n "browserName": "Microsoft Edge"\n }\n ]\n }\n}\nBuild info: version: \'3.141.59\', revision: \'e82be7d358\', time: \'20182be7d358\', 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.Driver info: driver.versversion: \'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.t org.openqa.selenium.reutil.Optional.orElseThrow(Unknown Source)\r\n\tat org.openqa.selenium.remote.server.NewSessionPipeline.lambda$createNewSession$5(NewSessionPipeline.java:75)\r\n\tat java.util.Oper.NewSessionPipeline.crtional.orElseGet(Unknown Source)\r\n\tat org.openqa.selenium.remote.server.NewSessionPipeline.createNewSession(NewSessionPipeline.java:73)\r\n\tat org.openqa.selenium.remote.ser.server.WebDriverServletver.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.e)\r\n\tat java.util.conutil.concurrent.Executors$RunnableAdapter.call(Unknown Source)\r\n\tat java.util.concurrent.FutureTask.run(Unknown Source)\r\n\tat java.util.concurrent.ThreadPoolExecutor.runWor, 'stackTrace': [{'fileNker(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': '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 ]\n }\n}\nBuild infot.ThreadPoolExecutor$Worker', 'lineNumber': -1}, {'fileName': None, 'methodName': 'run', 'className': 'java.lang.Thread', 'lineNumber': -1}], 'message': 'Unable to create sessio: \'x86\', os.version: \n from {\n "desiredCapabilities": {\n "browserName": "Microsoft Edge"\n },\n "capabilities": {\n "firstMatch": [\n {\n "browserName": "Microsoft Edge"\n
}\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>
原因分析:
根据日志可以得知从“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指定主流浏览器的名字是什么的。
posted on 2020-06-18 23:32 shiberhou 阅读(1049) 评论(0) 编辑 收藏 举报