0

谁能建议如何从 FirefoxDriver(功能)和 ChromeDriver(功能)中删除警告?

FIREFOX { @Override public DesiredCapabilities getDesiredCapabilities () { DesiredCapabilities 能力 = DesiredCapabilities.firefox (); 返回能力;}

    @Override
    public WebDriver getWebDriverObject (DesiredCapabilities capabilities)
    {   

        return new FirefoxDriver (capabilities);
    }
},

CHROME_Original
{
    @Override
    public DesiredCapabilities getDesiredCapabilities ()
    {
        DesiredCapabilities capabilities = DesiredCapabilities.chrome ();
        capabilities.setCapability ("chrome.switches", Arrays.asList ("--no-default-browser-check"));
        HashMap<String, String> chromePreferences = new HashMap<String, String> ();
        chromePreferences.put ("profile.password_manager_enabled", "false");
        capabilities.setCapability ("chrome.prefs", chromePreferences);
        return capabilities;
    }

    @Override
    public WebDriver getWebDriverObject (DesiredCapabilities capabilities)
    {
        return new ChromeDriver (capabilities);
    }
},
4

2 回答 2

0

尝试使用以下代码:

    ChromeOptions options = new ChromeOptions();
    options.setCapability("chrome.switches",Arrays.asList("--no-default-browser-check")); 
    HashMap<String, Boolean>chromePreferences = new HashMap<>(); 
    chromePreferences.put("profile.password_manager_enabled", false);
    options.setCapability("chrome.prefs", chromePreferences); 
    ChromeDriver driver = new ChromeDriver(options);

ChromeDriver 构造函数现在将 ChromeOptions 对象作为参数

于 2018-02-10T00:39:19.203 回答
0

直接操作DesiredCapabilities已被弃用,取而代之的是类型安全的“选项”类(FirefoxOptions InternetExplorerOptions等)。这样做的好处是可以帮助您避免为驱动程序设置不正确或无效的值。您可以通过更改代码以使用更新、更安全的结构来消除弃用警告。

于 2018-02-10T00:39:45.570 回答