selenium ChromeDriver 中的 options 參數設置


ChromeOptions options = new ChromeOptions();
options.BinaryLocation = sysPath + "/Chrome/Chrome.exe"; #設置瀏覽器程序位置                        

options.AddArgument("url=data:,");#設置啟動瀏覽器空白頁                                                             
options.AddArgument("--headless"); #隱藏瀏覽器                                                                 
options.SetLoggingPreference("off", LogLevel.Off); #禁止 console.log 日志輸出
IWebDriver driver = new ChromeDriver(sysPath + "/Chrome/", options);#設置chromedriver.exe 文件夾路徑
 
 
 
chrome_options.add_argument('--no-sandbox')#解決DevToolsActivePort文件不存在的報錯
 
chrome_options.add_argument('window-size=1920x3000') #指定瀏覽器分辨率
chrome_options.add_argument('--disable-gpu') #谷歌文檔提到需要加上這個屬性來規避bug
chrome_options.add_argument('--hide-scrollbars') #隱藏滾動條, 應對一些特殊頁面
chrome_options.add_argument('blink-settings=imagesEnabled=false') #不加載圖片, 提升速度
chrome_options.add_argument('--headless') #瀏覽器不提供可視化頁面. linux下如果系統不支持可視化不加這條會啟動失敗
 
詳細參數:https://peter.sh/experiments/chromium-command-line-switches/
        https://www.cnblogs.com/c-x-a/p/8572457.html
        https://www.cnblogs.com/yangjintao/p/10599868.html
        https://blog.csdn.net/qq_26200629/article/details/86141131
     


免責聲明!

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



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