Selenium(OSX和Linux)发生错误org.openqa.selenium.SessionNotCreatedException:未创建会话:未找到匹配功能

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Selenium(OSX和Linux)发生错误org.openqa.selenium.SessionNotCreatedException:未创建会话:未找到匹配功能相关的知识,希望对你有一定的参考价值。

我仅在OSX和Linux中收到此错误,但在Windows OS上运行正常

org.openqa.selenium.SessionNotCreatedException:未创建会话:未找到匹配功能内部版本信息:版本:'3.11.0',版本:'e59cfb3',时间:'2018-03-11T20:26:55.152Z'

硒版本:3.11.0Chrome版本:79.0.3945.130Chrome驱动程序版本:79.0.3945.36

下面是我代码中的chrome选项。如果您遇到此问题,请告诉我

case GlobalProperties.CHROME:
            System.setProperty("webdriver.chrome.driver",
                    PropertiesRepository.getString("global.browser.chrome.driver.executable"));
            cap = DesiredCapabilities.chrome();
            cap.setBrowserName(
                    PropertiesRepository.getString("global.browser.capability.browserName.ch"));
            cap.setjavascriptEnabled(true);
            cap.setCapability("platform",
                    PropertiesRepository.getString("global.browser.capability.platform"));
            cap.setCapability("takesScreenshot", PropertiesRepository
                    .getBoolean("global.browser.capability.chrome.takesScreenshot"));
            cap.setCapability("handlesAlerts", PropertiesRepository
                    .getBoolean("global.browser.capability.chrome.handlesAlerts"));
            cap.setCapability("cssSelectorsEnabled", PropertiesRepository
                    .getBoolean("global.browser.capability.chrome.cssSelectorsEnabled"));
            // Clearing session. 
            cap.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);

            // Opening incognito browser for clear cache. 
            cap.setCapability("chrome.switches", Arrays.asList("--incognito"));

            Map<String, Object> prefs = new HashMap<String, Object>();
            prefs.put("profile.default_content_settings.popups", 0);
            prefs.put("download.prompt_for_download", false);
            prefs.put("download.default_directory",
                    PropertiesRepository.getString("global.download.location"));

            ChromeOptions options = new ChromeOptions();
            options.addArguments("disable-infobars");
            options.addArguments("chrome.switches","--disable-extensions"); // To "Disable developer mode extensions"
            options.addArguments("--test-type");
            options.addArguments("--disable-extensions"); //to disable browser extension popup
            options.addArguments("--incognito");
            options.addArguments("--no-sanbox");
            options.addArguments("--headless");
            options.setBinary("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome");
            String extensions = PropertiesRepository
                    .getString("global.browser.capability.chrome.extensions");
            if (extensions != null && !extensions.trim().equals("")) 
                StringTokenizer tokens = new StringTokenizer(extensions, ",");
                String extensionPath = PropertiesRepository
                        .getString("global.browser.capability.chrome.extensionpath");
                File[] extFiles = new File[tokens.countTokens()];
                int i = 0;
                while (tokens.hasMoreElements()) 
                    extFiles[i] = new File(extensionPath + "/" + tokens.nextToken());
                    i++;
                
                options.addExtensions(extFiles);
            

            options.setExperimentalOption("prefs", prefs);

            cap.setCapability(ChromeOptions.CAPABILITY, options);
            cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
            cap.setCapability(ChromeOptions.CAPABILITY, options);
            break;

EXCEPTION

BROWSER : chrome
Jan 25, 2020 2:52:21 PM org.openqa.selenium.remote.DesiredCapabilities chrome
INFO: Using `new ChromeOptions()` is preferred to `DesiredCapabilities.chrome()`
 INFO [pool-1-thread-1] (DriverFactory.java:58) - Desired Capabilities : Capabilities acceptSslCerts: true, browserName: chrome, chrome.switches: [--incognito], cssSelectorsEnabled: true, ensureCleanSession: true, goog:chromeOptions: args: [disable-infobars, chrome.switches, --disable-extensions, --test-type, --disable-extensions, --incognito, --no-sanbox, --headless], binary: /Applications/Google Chrome..., extensions: [], prefs: download.default_directory: C:/download/ASMT, download.prompt_for_download: false, profile.default_content_settings.popups: 0, handlesAlerts: true, javascriptEnabled: true, platform: WINDOWS, takesScreenshot: true, version: 
 INFO [pool-1-thread-1] (DriverFactory.java:63) - environment value ==> stage
 INFO [pool-1-thread-3] (DriverFactory.java:58) - Desired Capabilities : Capabilities acceptSslCerts: true, browserName: chrome, chrome.switches: [--incognito], cssSelectorsEnabled: true, ensureCleanSession: true, goog:chromeOptions: args: [disable-infobars, chrome.switches, --disable-extensions, --test-type, --disable-extensions, --incognito, --no-sanbox, --headless], binary: /Applications/Google Chrome..., extensions: [], prefs: download.default_directory: C:/download/ASMT, download.prompt_for_download: false, profile.default_content_settings.popups: 0, handlesAlerts: true, javascriptEnabled: true, platform: WINDOWS, takesScreenshot: true, version: 
 INFO [pool-1-thread-3] (DriverFactory.java:63) - environment value ==> stage
Starting ChromeDriver 79.0.3945.36 (3582db32b33893869b8c1339e8f4d9ed1816f143-refs/branch-heads/3945@#614) on port 21174
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[1579985542.015][WARNING]: FromSockAddr failed on netmask
ERROR [pool-1-thread-2] (BaseTest.java:55) - Unable to load Driver
org.openqa.selenium.SessionNotCreatedException: session not created: No matching capabilities found
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z'
System info: host: 'ASC-C02YQ2BYLVDQ.local', ip: 'fe80:0:0:0:1c07:496e:1e2d:7ea7%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '1.8.0_231'
Driver info: driver.version: ChromeDriver
remote stacktrace: 0   chromedriver                        0x000000011001ce29 chromedriver + 3817001
1   chromedriver                        0x000000010ffb0f33 chromedriver + 3374899
2   chromedriver                        0x000000010fd318bf chromedriver + 755903
3   chromedriver                        0x000000010fcbc19e chromedriver + 274846
4   chromedriver                        0x000000010fcbb9d2 chromedriver + 272850
5   chromedriver                        0x000000010fcbce7d chromedriver + 278141
6   chromedriver                        0x000000010fcb9fa3 chromedriver + 266147
7   chromedriver                        0x000000010fc93c0d chromedriver + 109581
8   chromedriver                        0x000000010fc94ba5 chromedriver + 113573
9   chromedriver                        0x000000010ffdef6f chromedriver + 3563375
10  chromedriver                        0x000000010ffebe3a chromedriver + 3616314
11  chromedriver                        0x000000010ffebbf7 chromedriver + 3615735
12  chromedriver                        0x000000010ffbe699 chromedriver + 3430041
13  chromedriver                        0x000000010ffec692 chromedriver + 3618450
14  chromedriver                        0x000000010ffd2e17 chromedriver + 3513879
15  chromedriver                        0x0000000110001fe4 chromedriver + 3706852
16  chromedriver                        0x0000000110022fc7 chromedriver + 3841991
17  libsystem_pthread.dylib             0x00007fff715812eb _pthread_body + 126
18  libsystem_pthread.dylib             0x00007fff71584249 _pthread_start + 66
19  libsystem_pthread.dylib             0x00007fff7158040d thread_start + 13

    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.W3CHandshakeResponse.lambda$new$0(W3CHandshakeResponse.java:57)
    at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$getResponseFunction$2(W3CHandshakeResponse.java:104)
    at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
    at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:499)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:486)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
    at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:545)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:209)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:132)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:147)
    at com.ascendlearning.automation.ui.driver.DriverFactory$1.initialValue(DriverFactory.java:97)
    at com.ascendlearning.automation.ui.driver.DriverFactory$1.initialValue(DriverFactory.java:37)
    at java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:180)
    at java.lang.ThreadLocal.get(ThreadLocal.java:170)
    at com.ascendlearning.automation.ui.driver.DriverFactory.getDriver(DriverFactory.java:111)
    at com.ascendlearning.automation.ui.test.BaseTest.setup(BaseTest.java:51)
    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.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:517)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:601)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:845)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1153)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
 INFO [pool-1-thread-2] (BaseTest.java:59) - Method name in Base Test in setup for loading properties:ASMT746_VerifyQuizBankAndItsElements
 INFO [pool-1-thread-2] (PropertiesRepository.java:86) - List of files to load : stg_input.properties
 INFO [pool-1-thread-2] (PropertiesRepository.java:33) - Loading property file : stg_input.properties
java.lang.NullPointerException
    at com.ascendlearning.automation.ui.test.ExtentReport.takesScreenshot(ExtentReport.java:101)
    at com.ascendlearning.automation.ui.test.ExtentReport.onConfigurationFailure(ExtentReport.java:132)
    at org.testng.internal.Invoker.runConfigurationListeners(Invoker.java:1770)
    at org.testng.internal.Invoker.handleConfigurationFailure(Invoker.java:303)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:237)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:601)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:845)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1153)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
答案
此错误消息...

Jan 25, 2020 2:52:21 PM org.openqa.selenium.remote.DesiredCapabilities chrome INFO: Using `new ChromeOptions()` is preferred to `DesiredCapabilities.chrome()` INFO [pool-1-thread-1] (DriverFactory.java:58) - Desired Capabilities : Capabilities acceptSslCerts: true, browserName: chrome, chrome.switches: [--incognito], cssSelectorsEnabled: true, ensureCleanSession: true, goog:chromeOptions: args: [disable-infobars, chrome.switches, --disable-extensions, --test-type, --disable-extensions, --incognito, --no-sanbox, --headless], binary: /Applications/Google Chrome..., extensions: [], prefs: download.default_directory: C:/download/ASMT, download.prompt_for_download: false, profile.default_content_settings.popups: 0, handlesAlerts: true, javascriptEnabled: true, platform: WINDOWS, takesScreenshot: true, version: INFO [pool-1-thread-1] (DriverFactory.java:63) - environment value ==> stage INFO [pool-1-thread-3] (DriverFactory.java:58) - Desired Capabilities : Capabilities acceptSslCerts: true, browserName: chrome, chrome.switches: [--incognito], cssSelectorsEnabled: true, ensureCleanSession: true, goog:chromeOptions: args: [disable-infobars, chrome.switches, --disable-extensions, --test-type, --disable-extensions, --incognito, --no-sanbox, --headless], binary: /Applications/Google Chrome..., extensions: [], prefs: download.default_directory: C:/download/ASMT, download.prompt_for_download: false, profile.default_content_settings.popups: 0, handlesAlerts: true, javascriptEnabled: true, platform: WINDOWS, takesScreenshot: true, version: INFO [pool-1-thread-3] (DriverFactory.java:63) - environment value ==> stage Starting ChromeDriver 79.0.3945.36 (3582db32b33893869b8c1339e8f4d9ed1816f143-refs/branch-heads/3945@#614) on port 21174 Only local connections are allowed. Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code. [1579985542.015][WARNING]: FromSockAddr failed on netmask ERROR [pool-1-thread-2] (BaseTest.java:55) - Unable to load Driver org.openqa.selenium.SessionNotCreatedException: session not created: No matching capabilities found Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z' System info: host: 'ASC-C02YQ2BYLVDQ.local', ip: 'fe80:0:0:0:1c07:496e:1e2d:7ea7%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '1.8.0_231' Driver info: driver.version: ChromeDriver remote stacktrace: 0 chromedriver 0x000000011001ce29 chromedriver + 3817001 1 chromedriver 0x000000010ffb0f33 chromedriver + 3374899 2 chromedriver 0x000000010fd318bf chromedriver + 755903

...表示

ChromeDriver无法启动/产生新的Browsing Context,即Chrome Browser会话。

您的主要问题是正在使用的二进制版本之间的

incompatibility

,如下所示:
    您正在使用
  • chromedriver = 79.0
  • chromedriver=79.0的发行说明明确提到以下内容:
  • 支持

    Chrome版本79

    • 您的
    • Selenium Client版本是2018-03-11T20:26:55.152Z3.11.0,其版本几乎早了[[2
    年。]]因此,Selenium Client v3.11.0和

    chromedriver = 79.0

    之间明显不匹配”>解决方案
    确保:

    Clean您的
  • Project Workspace
  • 通过您的IDERebuild您的项目仅具有必需的依赖项。
    如果您的基本Web Client版本太旧,请通过Revo Uninstaller卸载它并安装最新的GA和
  • Web Client
  • 的发行版本。
    进行系统重启
  • 非root用户身份执行@Test。>>
  • 总是在driver.quit()方法中调用tearDown()以正常关闭并销毁WebDriver
  • Web Client实例。
  • 我能够自己解决此问题,其中所需的功能仍指向平台和默认下载目录的WINDOWS OS属性。因此,我已经修改了代码,以根据解决问题的操作系统设置这些值。
    所需功能:功能acceptSslCerts:true,浏览器名称:chrome,chrome.switches:[--incognito],cssSelectorsEnabled:true,sureCleanSession:true,goog:chromeOptions:args:[disable-infobars,chrome.switches,- -disable-extensions,--test-type,--disable-extensions,--incognito,--no-sanbox,--headless],二进制文件:/ Applications / Google Chrome ...,扩展名:[],首选项:

    download.default_directory:C:/ download / ASMT

    另一答案
    所需功能:功能acceptSslCerts:true,浏览器名称:chrome,chrome.switches:[--incognito],cssSelectorsEnabled:true,sureCleanSession:true,goog:chromeOptions:args:[disable-infobars,chrome.switches,- -disable-extensions,--test-type,--disable-extensions,--incognito,--no-sanbox,--headless],二进制文件:/ Applications / Google Chrome ...,扩展名:[],首选项:

    download.default_directory:C:/ download / ASMT

    以上是关于Selenium(OSX和Linux)发生错误org.openqa.selenium.SessionNotCreatedException:未创建会话:未找到匹配功能的主要内容,如果未能解决你的问题,请参考以下文章

    使用 selenium 和 webdriver (chrome) python OSX 在 Instagram 中填写登录表单

    发生动画时,Selenium FirefoxDriver 单击错误的链接

    如何解决这个错误发生在包selenium使用java?

    Selenium Hub 错误地认为 CLIENT_STOPPED_SESSION 已经发生

    如何让 Firefox 在 Mac OSX 上与 Selenium WebDriver 一起工作

    C ++的函数正则表达式在linux(CentOS)中但在OSX中遇到错误[重复]

    (c)2006-2024 SYSTEM All Rights Reserved IT常识