使用Selenium 3.8.1,不推荐使用Firefox,Chrome和IE驱动程序功能。

时间:2018-02-09 06:18:15

标签: selenium firefox selenium-webdriver selenium-chromedriver desiredcapabilities

任何人都可以建议如何从FirefoxDriver(功能)中删除警告 ChromeDriver(功能)?

FIREFOX     {         @覆盖         public DesiredCapabilities getDesiredCapabilities()         {             DesiredCapabilities capabilities = 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);
    }
},

2 个答案:

答案 0 :(得分: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对象作为参数

答案 1 :(得分:0)

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