【问题标题】:How to enable incognito mode in chrome when using selenium使用硒时如何在chrome中启用隐身模式
【发布时间】:2022-11-11 13:49:17
【问题描述】:

我已添加 options.addArguments("--incognito"); 以使用 chrome incognito。但是我收到以下错误:

Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start: crashed.
  (chrome not reachable)
  (The process started from chrome location C:\Program Files\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.) 
Host info: host: 'LAP-10119', ip: '10.97.198.8'
Build info: version: '4.5.0', revision: 'fe167b119a'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '18.0.2.1'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [--disable-application-cache, --incognito, --no-sandbox, --disable-dev-shm-usage, --disable-application-cache], extensions: [], prefs: {download.default_directory: C:\AutomationFramework\mvn-..., profile.default_content_settings.popups: 0}}}], desiredCapabilities=Capabilities {browserName: chrome, goog:chromeOptions: {args: [--disable-application-cache, --incognito, --no-sandbox, --disable-dev-shm-usage, --disable-application-cache], extensions: [], prefs: {download.default_directory: C:\AutomationFramework\mvn-..., profile.default_content_settings.popups: 0}}}}]
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:144)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:102)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:67)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:156)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:167)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:142)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:547)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:242)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:157)
    at org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver.java:101)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:81)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:70)
    at com.company.IniWebDriver.OpenBrowser(IniWebDriver.java:139)
    at com.company.Main.main(Main.java:306)

代码:

ChromeOptions options = new ChromeOptions();
options.addArguments("--incognito");

chrome版本为106.0.5249.119,chrome驱动版本为106.0.5249.61。

有没有其他方法可以在不使用 ChromeOptions 的情况下使用隐身模式? chromedriver 更新后,chrome incognito 停止工作。

【问题讨论】:

    标签: java selenium selenium-chromedriver


    【解决方案1】:

    您是否为功能添加了选项?

    ChromeOptions options = new ChromeOptions();
    options.addArguments("--incognito");
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    WebDriver chromedriver=new ChromeDriver(capabilities);
    

    【讨论】:

    • 是的,我已经添加但仍然是同样的错误
    • 你有 selenium docker 容器还是独立的?
    • 它是独立的
    猜你喜欢
    • 2021-01-09
    • 2021-06-01
    • 2013-06-30
    • 1970-01-01
    • 1970-01-01
    • 2012-08-05
    • 2015-02-16
    • 2013-09-24
    • 2017-08-14
    相关资源
    最近更新 更多