2017-10-10 101 views
1

我試圖在www.naukri.com中處理多個彈出窗口阻止程序;爲此,我在firefox中創建了一個名爲「AutoProfile」的自定義配置文件。但我在加載這個自定義配置文件在Firefox的驅動程序有問題;無法在FirefoxDriver中加載自定義配置文件:構造函數FirefoxDriver(Firefox配置文件)未定義

System.setProperty("webdriver.gecko.driver", "F:\\abc\\geckodriver-v0.18.0-win64\\geckodriver.exe"); 
ProfilesIni profile2=new ProfilesIni(); 
FirefoxProfile profile3=profile2.getProfile("AutoProfile"); 
profile3.setPreference("browser.popups.showPopupBlocker", false); 
driver =new FirefoxDriver(profile3); 
driver.get("www.naukri.com"); 

但我得到一個錯誤在driver=new FirefoxDriver(profile3);它說:

The constructor FirefoxDriver(FirefoxProfile) is undefined. 

有些時候,我得到一個消息作爲構造已被棄用。

回答

0

這個問題是由於舊的硒版本並存。 mvn clean install解決了這個問題。

更新壁虎驅動器和庫

希望您的問題將得到解決

什麼是硒Geckodriver的版本,您使用的
+0

感謝您的回覆,我沒有下載最新的磁帶庫和驅動器壁虎。但問題仍然存在.. –

0

https://raw.githubusercontent.com/SeleniumHQ/selenium/master/rb/CHANGES

3.4.1 (2017-06-13) 
================== 
Firefox: 
    * Added new Firefox::Options class that should be used to customize browser 
    behavior (command line arguments, profile, preferences, Firefox binary, etc.). 
    The instance of options class can be passed to driver initialization using 
    :options key. Old way of passing these customization directly to driver 
    initialization is deprecated. 

爲了設置配置文件,你應該做這樣的事情:

  System.setProperty("webdriver.gecko.driver", "F:\\abc\\geckodriver-v0.18.0-win64\\geckodriver.exe"); 
     ProfilesIni profile2 = new ProfilesIni(); 
     FirefoxProfile profile3 = profile2.getProfile("AutoProfile"); 
     profile3.setPreference("browser.popups.showPopupBlocker", false); 

     FirefoxOptions firefoxOptions = new FirefoxOptions(); 
     firefoxOptions.setProfile(profile3); 

     WebDriver driver = new FirefoxDriver(firefoxOptions); 
     driver.get("www.naukri.com"); 
+0

謝謝你的回覆..它確實解決了我的問題。再次感謝你! –

+0

@JohnDoe樂於幫忙,歡迎來到Stack Overflow。如果此答案或任何其他人解決了您的問題,請將其標記爲已接受:stackoverflow.com/help/someone-answers –