亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 Selenium Webdriver 3 中為 Firefox 驅動程序設置默認配置文件?

如何在 Selenium Webdriver 3 中為 Firefox 驅動程序設置默認配置文件?

慕哥9229398 2021-10-06 10:57:38
我無法在 Selenium 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");    }}
查看完整描述

2 回答

?
開心每一天1111

TA貢獻1836條經驗 獲得超13個贊

將您的設置移至 @BeforeClass


我正在使用此設置,效果很好:


@BeforeClass

public static void setUpClass() {

    FirefoxOptions options = new FirefoxOptions();

    ProfilesIni allProfiles = new ProfilesIni();         

    FirefoxProfile selenium_profile = allProfiles.getProfile("selenium_profile");

    options.setProfile(selenium_profile);

    options.setBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");

    System.setProperty("webdriver.gecko.driver", "C:\\Users\\pburgr\\Desktop\\geckodriver-v0.20.0-win64\\geckodriver.exe");

    driver = new FirefoxDriver(options);

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

只需更改路徑和配置文件名稱。


查看完整回答
反對 回復 2021-10-06
  • 2 回答
  • 0 關注
  • 282 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號