selenium啟動Chrome瀏覽器和禁止證書錯誤提示彈出


要把ChromeDriver放到代碼中的文件夾中c://*******Application

    public static WebDriver WebDriverRun(WebDriver driver){
//            System.setProperty(Dom4jXml.getValue("chromeDriverName"), Dom4jXml.getValue("chromeDriverPath"));
            // 設置 chrome 的路徑  
            System.setProperty(  
                "webdriver.chrome.driver",  
                "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");  
            webdriver = new ChromeDriver(chromeOptions());
            
            // 轉型為WebDriver, 統一類型,方便調用異常截圖方法
            RuntimeServer runtime = new RuntimeServer();
            runtime.runtimeDriver(webdriver);
//            driver = chromeOptions();
            //driver = new FirefoxDriver();
            return webdriver;
    }
    
    /**
     * 禁止chrome彈出忽略網站證書錯誤提示
     * @return
     */
    public static ChromeOptions chromeOptions(){
            ChromeOptions options = new ChromeOptions();
//            DesiredCapabilities capabilities = DesiredCapabilities.chrome();
//            capabilities.setCapability("chrome.switches", Arrays.asList("--start-maximized"));
//            options.addArguments("--test-type", "--start-maximized");
            options.addArguments("--test-type", "--ignore-certificate-errors");
            
            return options;
    }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM