![](/img/trans.png)
[英]What is the difference between the Selenium methods - maximize() and fullscreen()
[英]In Selenium Java client what is the difference between addArguments and setPreference methods?
當使用 Java 和 Selenium 時,經常當我在谷歌上搜索如何更改某個行為時,我會找到一些示例來解釋如何使用 addArgument 或 set_preferences 更改設置,如下所示:
options.addArguments("dom.webdriver.enabled=False");
options.addArguments("useAutomationExtension=False");
profile.setPreference("dom.webdriver.enabled", False);
profile.setPreference("useAutomationExtension", False);
查看 Javadoc 並不是很有幫助:
有人可以解釋這些之間的關系嗎? 有什么概念上的區別嗎? 它們看起來非常重疊。
此外, desiredCapabilities
的能力和capabilities
看起來也非常相似。 為什么這些存在以及它們如何相互關聯?
https://www.chromium.org/administrators/configuring-other-preferences
首選項是用於控制瀏覽器行為的設置,支持的首選項的完整列表可以在以下位置找到:
https://chromium.googlesource.com/chromium/src/+/master/chrome/common/pref_names.cc
arguments 是可以作為命令行 arguments 傳遞到 chrome 二進制文件的命令,例如
chrome.exe --headless
完整列表: https://peter.sh/experiments/chromium-command-line-switches/
對於 firefox:
Arguments: https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options
在 firefox 配置中添加所有設置(您可以通過在地址欄中鍵入 about:config 來訪問)可以使用 options.addPreference 進行設置
addArguments()
是配置 AbstractDriverOptions 以管理 firefox 特定設置的方法,geckodriver 可以使用FirefoxOptions Class 的實例來理解。
舉個例子:
FirefoxOptions option=new FirefoxOptions();
options.addArguments("start-maximized");
setPreference()
是使用 FirefoxProfile Class 實例以geckodriver可以理解的方式配置 firefox 配置文件特定設置的方法。
舉個例子:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.dir", "/home/ranjith/Downloads");
profile.setPreference("browser.download.folderList", 2);
您可以在以下位置找到一些相關的詳細討論:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.