日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

selenium操作chrome时的一些配置

發布時間:2024/1/17 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 selenium操作chrome时的一些配置 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
收集的一些selenium chrome配置信息: 一些Chrome的地址欄命令(這些命令會不停的變動,所有不一定都是好用的) 在Chrome的瀏覽器地址欄中輸入以下命令,就會返回相應的結果。這些命令包括查看內存狀態,瀏覽器狀態,網絡狀態,DNS服務器狀態,插件緩存等等。 about:version - 顯示當前版本 about:memory - 顯示本機瀏覽器內存使用狀況 about:plugins - 顯示已安裝插件 about:histograms - 顯示歷史記錄 about:dns - 顯示DNS狀態 about:cache - 顯示緩存頁面 about:gpu -是否有硬件加速 about:flags -開啟一些插件 //使用后彈出這么些東西:“請小心,這些實驗可能有風險”,不知會不會搞亂俺的配置啊! chrome://extensions/ - 查看已經安裝的擴展 其他的一些關于Chrome的實用參數及簡要的中文說明(使用方法同上,當然也可以在shell中使用) –user-data-dir=”[PATH]” 指定用戶文件夾User Data路徑,可以把書簽這樣的用戶數據保存在系統分區以外的分區。 –disk-cache-dir=”[PATH]“ 指定緩存Cache路徑 –disk-cache-size= 指定Cache大小,單位Byte –first run 重置到初始狀態,第一次運行 –incognito 隱身模式啟動 –disable-javascript 禁用Javascript --omnibox-popup-count="num" 將地址欄彈出的提示菜單數量改為num個。我都改為15個了。 --user-agent="xxxxxxxx" 修改HTTP請求頭部的Agent字符串,可以通過about:version頁面查看修改效果 --disable-plugins 禁止加載所有插件,可以增加速度??梢酝ㄟ^about:plugins頁面查看效果 --disable-javascript 禁用JavaScript,如果覺得速度慢在加上這個 --disable-java 禁用java --start-maximized 啟動就最大化 --no-sandbox 取消沙盒模式 --single-process 單進程運行 --process-per-tab 每個標簽使用單獨進程 --process-per-site 每個站點使用單獨進程 --in-process-plugins 插件不啟用單獨進程 --disable-popup-blocking 禁用彈出攔截 --disable-plugins 禁用插件 --disable-images 禁用圖像 --incognito 啟動進入隱身模式 --enable-udd-profiles 啟用賬戶切換菜單 --proxy-pac-url 使用pac代理 [via 1/2] --lang=zh-CN 設置語言為簡體中文 --disk-cache-dir 自定義緩存目錄 --disk-cache-size 自定義緩存最大值(單位byte) --media-cache-size 自定義多媒體緩存最大值(單位byte) --bookmark-menu 在工具 欄增加一個書簽按鈕 --enable-sync 啟用書簽同步

? private void getChromeDriver() {
? ? Config config = new ConfigProvider().get();
? ??
? ? Config configToUse = Optional.ofNullable(config).orElse(ConfigLoader.load());
? ? prepareChromeDriver(configToUse);


? ? final String osName = config.getString("os.name");
? ? ChromeOptions chromeOptions = new ChromeOptions();
? ? if (StringUtils.containsIgnoreCase(osName, "windows")) { // 本地Windows環境, 初始化local環境的chrome driver
? ? ? logger.info("windows環境", osName);
? ? ? chromeOptions.setBinary(configToUse.getString("webdriver.chrome.binary")); // windows下chrome地址
? ? ? chromeOptions.addArguments("--profile-directory=target");
? ? ? chromeOptions.addArguments("--user-data-dir=target\\");
? ? } else { // FAT/UAT/PROD等Linux環境, 初始化Linux環境的chrome driver
? ? ? logger.info("Linux環境", osName);
? ? ? chromeOptions.setBinary("/usr/bin/google-chrome-stable"); // 配置chrome安裝地址
? ? ? chromeOptions.addArguments("--headless");
? ? ? chromeOptions.addArguments("--disable-gpu");
? ? ? String proxyServer = qconfigService.getConfig("proxyHost") + ":" + qconfigService.getConfig("proxyPort"); //代理配置
? ? ? chromeOptions.addArguments("--proxy-server=" + proxyServer);
? ? }
? ? chromeOptions.addArguments("--incognito"); // 打開隱私模式
? ? chromeOptions.addArguments("--lang=" + chineses); // 中文
? ? chromeOptions.addArguments("-test-type", "--ignore-certificate-errors"); // 忽略證書錯誤
? ? chromeOptions.addArguments("--no-sandbox");


//? ? 添加chrome模擬器
//? ? Map<String, String> mobileEmulation = new HashMap<String, String>();
//? ? mobileEmulation.put("deviceName", "Galaxy S5");//"Nexus 5X");
//? ? chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
? ??
? ? String webDriverPath = System.getProperty("webdriver.chrome.driver");
? ? ChromeDriverService driverService = new ChromeDriverService.Builder().usingDriverExecutable(new File(webDriverPath)).usingAnyFreePort().build();
? ? try {
? ? ? driverService.start();
? ? } catch (IOException e) {
? ? ? logger.error(e);
? ? }
? ? logger.info("webdriver.chrome.driver", webDriverPath);
? ? ChromeDriver driver = new ChromeDriver(driverService, chromeOptions);
? ? logger.info("webdriver.chrome.driver", webDriverPath);
? }

總結

以上是生活随笔為你收集整理的selenium操作chrome时的一些配置的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。