小编Dru*_*Cat的帖子

Selenium chromedriver禁用日志记录或将其重定向到Java

我正在尝试在小型Web搜寻器中使用Selenium来获取页面源。我的输出日志受到硒日志的入侵,有没有一种方法可以完全禁用日志记录,或者只是以某种方式将其重定向到/ dev / null?

日志消息是:

Starting ChromeDriver 2.43.600233 
(523efee95e3d68b8719b3a1c83051aa63aa6b10d) on port 1628
Only local connections are allowed.
ott 24, 2018 7:52:01 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFORMAZIONI: Detected dialect: OSS
Run Code Online (Sandbox Code Playgroud)

我通过以下方式调用驱动程序:

WebDriver driver = null;
            try {
            System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver");
            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions.setBinary("/usr/bin/chromium");
            chromeOptions.addArguments("--headless");
            chromeOptions.addArguments("--silent");
            chromeOptions.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE);
            driver = new ChromeDriver(chromeOptions);
            /*FirefoxBinary firefoxBinary = new FirefoxBinary();
            firefoxBinary.addCommandLineOptions("--headless");
            System.setProperty("webdriver.gecko.driver", "/usr/local/bin/geckodriver");
            System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE, "true");
            System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "/dev/null");


            FirefoxOptions firefoxOptions = new FirefoxOptions();
            firefoxOptions.setBinary(firefoxBinary);
            FirefoxDriver driver = new FirefoxDriver(firefoxOptions);*/
            if(driver!=null) {
            driver.get(link);
Run Code Online (Sandbox Code Playgroud)

java logging selenium selenium-chromedriver

3
推荐指数
2
解决办法
2253
查看次数

标签 统计

java ×1

logging ×1

selenium ×1

selenium-chromedriver ×1