我正在制作一个小型的Java应用程序,它需要在隐藏模式下打开Firefox浏览器,并将其静音。
从下面的代码中可以看到,我已经找到了隐藏浏览器的方法。然而,我正在弄清楚一些问题,如何将浏览器静音,以及是否实际上可以做到这一点。
考虑到下面的answer,我认为这可能是可能的,我知道答案是Python的,但它使用selenium webdriver,然而对于Chrome,我需要它的Firefox。
我试着插入下面这行firefoxBinary.addCommandLineOptions("--mute-audio");,但是似乎行不通。
以下是我目前所拥有的。
WebDriver driver;
FirefoxBinary firefoxBinary = new FirefoxBinary();
firefoxBinary.addCommandLineOptions("--headless");
System.setProperty("webdriver.gecko.driver", driverPath);
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setBinary(firefoxBinary);
driver = new FirefoxDriver(firefoxOptions);发布于 2018-03-13 05:22:49
经过进一步的研究,下面的代码使用Selenium修复了Java中静音Geckodriver的问题。我在上面脚本的firefoxOptions.setBinary(firefoxBinary);行下面添加了这段代码。
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("media.volume_scale", "0.0");
firefoxOptions.setProfile(firefoxProfile);https://stackoverflow.com/questions/49200017
复制相似问题