标题: [Selenium] 通过第三方脚本 处理windows Pop-Up Dialog的一种解决方案 [打印本页] 作者: 欺负人 时间: 2009-12-15 12:42 标题: [Selenium] 通过第三方脚本 处理windows Pop-Up Dialog的一种解决方案 昨天晚上闲着没事做,个人觉得Selenium对pop-up dialog的支持不太好,所以自己就打算通过第三方的脚本去实现这个东西,下面是其中的一个方案,It does work, and Hope it can help some guys,主要是基于Windows 底层的UIautomationClient,UIAutomationProvider &UIautomationTypes等,大概的Code 如下:
using System;
using System.Collections.Generic;
using System.Linq;
using Internal.Mita.Foundation;
using Internal.Mita.Foundation.Controls;
/// <summary>
/// This class represents the save file dialog
/// </summary>
public class SaveDialogWrapper
{
public SaveDialogWrapper(UIObject dialogUIObject)
{
this.dialogUIObject = dialogUIObject;
FileNameEdit = new Edit(SilverLightElements.GetUIObject(
dialogUIObject.Descendants, Edit));
/// <summary>
/// User click the cancel button
/// </summary>
public void CancelFile()
{
CancelBtn.Click();
}
/// <summary>
/// User type in file name and then click the save file button
/// </summary>
/// <param name="filePath"></param>
public void SaveFile(string filePath)
{
FileNameEdit.SetValue(filePath);
SaveBtn.Click();
}
/// <summary>
/// User click the save file button, the file name is by default, the file will
/// be saved in disk C:
/// </summary>
/// <returns></returns>
public string SaveDefaultFile()
{
string filePath = @"C:\{0}";
/// <summary>
/// This method is for future use. It is not used now.
/// </summary>
/// <returns></returns>
private DownLoadCompletedDialog LaunchSaveCompleteDialog()
{
WindowOpenedWaiter waiter = null;
UICondition condition = UICondition.CreateFromClassName(
UIHelper.DownLoadClassName).AndWith(
UICondition.CreateFromName(UIHelper.DownloadComplete));
waiter = new WindowOpenedWaiter(condition);
bool isDialogOpened = false;
SaveBtn.Click();
for (int i = 0; i < ExportContants.DownLoadRetry && !isDialogOpened; i++)
{
waiter.Reset();
waiter = new WindowOpenedWaiter(condition);
isDialogOpened = waiter.TryWait();
}
DownLoadCompletedDialog download = new DownLoadCompletedDialog(waiter.Source);
return download;
}