如何解决日志信息在 selenium 项目中使用 `new FirefoxOptions()` 优于 `DesiredCapabilities.firefox()`

Ada*_*mar 5 java firefox selenium selenium-webdriver geckodriver

我刚刚开始了一个 selenium 项目,但事情并不顺利,所以在搜索了一下之后我找到了这个解决方案。它有效,但我无法理解这些红色声明要我做什么,或者如何摆脱它们。

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.io.*;

public class SelTest1
{
    public  static void main(String [] args)
    {
        System.setProperty("webdriver.gecko.driver","X:\\Gecko\\geckodriver-v0.24.0-win64\\geckodriver.exe");

        File pathBinary = new File("X:\\FireFoxx\\firefox.exe");
        FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);
        DesiredCapabilities desired = DesiredCapabilities.firefox();
        FirefoxOptions options = new FirefoxOptions();
        desired.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options.setBinary(firefoxBinary));
        WebDriver obj = new FirefoxDriver(options);

        obj.get("http://www.google.com/");
    }
}
Run Code Online (Sandbox Code Playgroud)

这张图片有那些红线

我得到了我想要的结果,但我不明白警告{红色声明}

我把那些红线{警告也放在这里为了方便}

Jul 12, 2019 7:07:28 PM org.openqa.selenium.remote.DesiredCapabilities firefox
INFO: Using `new FirefoxOptions()` is preferred to `DesiredCapabilities.firefox()`
1562938650997   mozrunner::runner   INFO    Running command: "X:\\FireFoxx\\firefox.exe" "-marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\adars\\AppData\\Local\\Temp\\rust_mozprofile.uTUmeENutxin"
1562938652637   addons.webextension.screenshots@mozilla.org WARN    Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons
1562938652638   addons.webextension.screenshots@mozilla.org WARN    Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/
1562938652638   addons.webextension.screenshots@mozilla.org WARN    Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: about:reader*
1562938655909   Marionette  INFO    Listening on port 50040
1562938655964   Marionette  WARN    TLS certificate errors will be ignored for this session
Jul 12, 2019 7:07:36 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Run Code Online (Sandbox Code Playgroud)

Deb*_*anB 6

信息日志消息:

INFO: Using `new FirefoxOptions()` is preferred to `DesiredCapabilities.firefox()`
Run Code Online (Sandbox Code Playgroud)

是包含在以下内容中的更改的结果:


如果您的用例要明确提及 的绝对位置,FirefoxBinary您可以使用以下解决方案:

  • 使用FirefoxOptions

    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.firefox.FirefoxOptions;
    
    public class A_Firefox_binary 
    {
        public static void main(String[] args) 
        {
            System.setProperty("webdriver.gecko.driver", "C:/Utility/BrowserDrivers/geckodriver.exe");
            FirefoxOptions options = new FirefoxOptions();
            options.setBinary("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
            WebDriver driver =  new FirefoxDriver(options);
            driver.get("https://stackoverflow.com");
            System.out.println("Page Title is : "+driver.getTitle());
            driver.quit();
        }
    }
    
    Run Code Online (Sandbox Code Playgroud)
  • 控制台输出:

    Page Title is : Stack Overflow - Where Developers Learn, Share, & Build Careers
    
    Run Code Online (Sandbox Code Playgroud)