gpt4 book ai didi

java - 在 Selenium 项目中,与 `new FirefoxOptions()`相比,如何使用 `DesiredCapabilities.firefox()`寻址日志信息更为可取

转载 作者:行者123 更新时间:2023-12-03 19:35:03 28 4
gpt4 key购买 nike

我刚开始一个 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/");
}
}

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

我将这些红线放在{此处也警告方便}
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

最佳答案

此信息日志消息:

INFO: Using `new FirefoxOptions()` is preferred to `DesiredCapabilities.firefox()`

是合并在以下内容中的结果:
  • Selenium v​​3.0.0-beta4
    Added ability to use FirefoxOptions when starting firefox.
  • Selenium v​​3.5.0
    * Start making *Option classes instances of Capabilities. This allows
    the user to do:

    `WebDriver driver = new RemoteWebDriver(new InternetExplorerOptions());`


  • 如果您的用例是要明确提及 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();
    }
    }
  • 控制台输出:
    Page Title is : Stack Overflow - Where Developers Learn, Share, & Build Careers
  • 关于java - 在 Selenium 项目中,与 `new FirefoxOptions()`相比,如何使用 `DesiredCapabilities.firefox()`寻址日志信息更为可取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57008561/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com