どのように私はセレンwebdriverを3にFirefoxのドライバのデフォルトのプロファイルを設定することができますか?

Vladyslav Kuhivchak:

中にはそのようなコンストラクタが存在しないので、私はセレンwebdriverを3でのFirefoxのデフォルトのプロファイルを設定することはできませんFirefoxDriverクラスが。

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.ProfilesIni;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class SeleniumStartTest {
    @Test
    public void seleniumFirefox() {
        System.setProperty("webdriver.gecko.driver", "C:\\Users\\FirefoxDriver\\geckodriver.exe");
        ProfilesIni profileIni = new ProfilesIni();
        FirefoxProfile profile = profileIni.getProfile("default");
        WebDriver driver = new FirefoxDriver(profile);
        driver.get("http://www.google.com");
    }
}

Javaコードでコンパイルエラー:Javaコード

Mavenのpom.xml依存関係:セレン3.14.0

Firefoxのバージョン:Firefoxバージョン62.0.2

DebanjanB:

使用しているとして、セレン3.14.0を通りFirefoxDriverクラスの有効なコンストラクタは、以下のとおりです。

  • FirefoxDriver()
  • FirefoxDriver(FirefoxOptions options)
  • FirefoxDriver(GeckoDriverService service)
  • FirefoxDriver(GeckoDriverService service, FirefoxOptions options)
  • FirefoxDriver(XpiDriverService service)
  • FirefoxDriver(XpiDriverService service, FirefoxOptions options)

だから、あなたのコードの試みごとに次のように起動するための有効なオプションではありません FirefoxDriver()

WebDriver driver = new FirefoxDriver(profile);

解決

呼び出し起動するにFirefoxDriver()してデフォルトのプロファイルあなたが使用する必要がありますsetProfile(profile)設定する方法をFirefoxProfileをのインスタンスを通じてFirefoxOptions()、あなたが次のコードブロックを使用することができます。

  • コードブロック:

    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.firefox.FirefoxOptions;
    import org.openqa.selenium.firefox.FirefoxProfile;
    import org.openqa.selenium.firefox.ProfilesIni;
    import org.testng.annotations.Test;
    
    public class A_FirefoxProfile {
    
          @Test
          public void seleniumFirefox() {
            System.setProperty("webdriver.gecko.driver", "C:/Utility/BrowserDrivers/geckodriver.exe");
            ProfilesIni profileIni = new ProfilesIni();
            FirefoxProfile profile = profileIni.getProfile("default");
            FirefoxOptions options = new FirefoxOptions();
            options.setProfile(profile);
            WebDriver driver = new FirefoxDriver(options);
            driver.get("http://www.google.com");
            System.out.println(driver.getTitle());
          }
    
    }
    
  • コンソール出力:

    [RemoteTestNG] detected TestNG version 6.14.2
    1537775040906   geckodriver INFO    geckodriver 0.20.1
    1537775040923   geckodriver INFO    Listening on 127.0.0.1:28133
    Sep 24, 2018 1:14:30 PM org.openqa.selenium.remote.ProtocolHandshake createSession
    INFO: Detected dialect: W3C
    Google
    PASSED: seleniumFirefox
    
    ===============================================
        Default test
        Tests run: 1, Failures: 0, Skips: 0
    ===============================================
    
    
    ===============================================
    Default suite
    Total tests run: 1, Failures: 0, Skips: 0
    ===============================================
    

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=192661&siteId=1