2012-11-05 75 views
0

如何使用WebDriver單擊接受/解除unhandledalerts?如何使用WebDriver接受/解除未處理的警報?

是否有可能以檢查未處理的警報來了?

我如何使用UNEXPECTED_ALERT_BEHAVIOUR能力?它沒有按我的預期工作?

我已經試過這樣

DesiredCapabilities dc = DesiredCapabilities.firefox(); 
dc.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, "Accept"); 

回答

3

試試這個代碼:

WebDriver driver; 
@BeforeClass 
public void setUp() { 

    DesiredCapabilities dc=new DesiredCapabilities(); 
    dc.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR,UnexpectedAlertBehaviour.ACCEPT); 
    driver =new FirefoxDriver(dc); 
} 

我希望這將是有益的給你。

+0

謝謝ABHI的答覆。但是,上面的事情也不像我們預期的那樣工作。你有沒有嘗試過上述邏輯? – Santoshsarma

+0

你面臨什麼問題?上面的邏輯對我來說工作得很好(見編輯答案)。 –

+0

我預計一樣,如果有任何未處理的警告目前它應該接受(點擊OK)。但,它不是happening.It拋出UnhandledAlertException。 – Santoshsarma

0

打開Firefox,並嘗試 'about:config中'。

Findout哪個偏好名稱可以解決你的問題,使用下面的代碼進行相應的設置值。例如:我正在禁用Firefox的自動更新。

FirefoxProfile profile = new FirefoxProfile(); 
    profile.setPreference("app.update.enabled", false); 
    WebDriver driver = new FirefoxDriver(profile); 
+0

謝謝阿南德..!我會尋找那..但是,如果你發現任何地方,請不要忘記在這裏發佈。 – Santoshsarma

相關問題