2016-09-19 81 views
1

我在啓動firefox驅動程序時加入了firebug,它在最新的selenium web驅動程序3.0中工作得很好,但同時它也在每次啓動瀏覽器時打開新的firebug選項卡。如何使用螢火蟲啓動硒火狐webdriver時自動關閉螢火蟲標籤?

正如代碼所說,我已經包含firebug文件並在創建的配置文件中添加了此擴展名。啓動瀏覽器後,有沒有辦法自動關閉螢火蟲標籤?如果沒有自動方式,那麼我需要使用調整來關閉名爲「Firebug」的窗口吧?

代碼:

File file = new File("./firebug-2.0.17-fx.xpi"); 
System.setProperty("webdriver.gecko.driver", config.getStringProperty("geckodriver.path")); 
DesiredCapabilities capabilities = DesiredCapabilities.firefox(); 
FirefoxProfile profile = new FirefoxProfile(); 
profile.addExtension(file); 
capabilities.setCapability(FirefoxDriver.PROFILE, profile); 
capabilities.setCapability("marionette", true); 
webDriver = new FirefoxDriver(capabilities); 

enter image description here

+0

你試過http://stackoverflow.com/questions/11449179/how-can-i-close-a-specific-window-using-selenium- webdriver與Java? – lauda

+0

我已經在初步評論中已經添加,我正在尋找自動解決方案,但無論如何需要通過打開的窗口處理:)發佈答案... –

回答

1

您可以設置 「showFirstRunPage」 標誌爲 「假」 在你的porfile。

FirefoxProfile profile = new FirefoxProfile(); 
profile.setPreference("extensions.firebug.showFirstRunPage", false); 

以下是您可以設置的所有Firebug偏好設置的鏈接。 Firebug Preferences

另一種解決方法是將「currentVersion」設置爲這樣的大數字。

profile.setPreference("extensions.firebug.currentVersion", "999"); 

我寧願先上;)

+0

非常棒!請接受這個問題。 –

0

我一直在尋找自動關閉Firebug的窗口,但我認爲它不可能如此張貼的答案啓動燃燒室瀏覽器與螢火功能後處理打開的窗口,不幸的是你需要處理額外的代碼由於這個問題:)

下面的解決方案,它工作正常,只需使用它如下:

工作代碼:

File file = new File("./firebug-2.0.17-fx.xpi"); 
System.setProperty("webdriver.gecko.driver", config.getStringProperty("geckodriver.path")); 
DesiredCapabilities capabilities = DesiredCapabilities.firefox(); 
FirefoxProfile profile = new FirefoxProfile(); 
profile.addExtension(file); 
capabilities.setCapability(FirefoxDriver.PROFILE, profile); 
capabilities.setCapability("marionette", true); 
webDriver = new FirefoxDriver(capabilities); 

// Close the firebug window 
Thread.sleep(4000); // Firebug window takes time to open it 
Set <String> windows = webDriver.getWindowHandles(); 
String mainwindow = webDriver.getWindowHandle(); 

for (String handle: windows) { 
    webDriver.switchTo().window(handle); 
    if (!handle.equals(mainwindow)) { 
     webDriver.close(); 
    } 
} 
webDriver.switchTo().window(mainwindow);