【问题标题】:How to fix a Deprecation Warning, Firefox ProfilesIni has been deprecated in java如何修复弃用警告,Firefox ProfilesIni 已在 java 中弃用
【发布时间】:2022-01-20 06:25:02
【问题描述】:

我想使用我的自定义 Firefox 配置文件,但我收到了弃用警告

ProfilesIni myProfile = new ProfilesIni();

@SuppressWarnings。我该如何解决这个问题。

import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.openqa.selenium.firefox.FirefoxProfile;

//System.setProperty("C:\\driver\\geckodriver.exe");

ProfilesIni myProfile = new ProfilesIni();

FirefoxProfile test = myProfile.getProfile("selenium 1");

WebDriver driver = new FirefoxDriver(test);

driver.manage().window().maximize();

driver.get("https://www.google.com");

【问题讨论】:

    标签: java selenium selenium-firefoxdriver suppress-warnings deprecation-warning


    【解决方案1】:

    只需使用javadoc 中提到的较新类:

    已弃用。 请改用 org.openqa.selenium.firefox.ProfilesIni。

    而不是 org.openqa.selenium.firefox.internal.ProfilesIni 利用 org.openqa.selenium.firefox.ProfilesIni.

    【讨论】:

      【解决方案2】:

      注意有两个名为 ProfilesIni 的类

      org.openqa.selenium.firefox.ProfilesIni
      org.openqa.selenium.firefox.internal.ProfilesIni
      

      你可以禁止类警告:

      @SuppressWarnings("deprecation")
      public class YourClass {
         ...
      }
      

      或方法:

      @SuppressWarnings("deprecation")
      public void foo() {
         ...
      }
      
      @SuppressWarnings("deprecation")
      public WebDriver startGeckoDriver() {
         WebDriver driver = ...;
         return driver;
      }
      

      myProfile

      @SuppressWarnings("deprecation")
      ProfilesIni myProfile = new ProfilesIni();
      

      在 Eclipse 中,您可以使用黄色警告图标添加注释:

      【讨论】:

        猜你喜欢
        • 2015-12-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-07-29
        • 1970-01-01
        • 1970-01-01
        • 2023-04-07
        相关资源
        最近更新 更多