Hi friends,
I am using Autoit in my C# application(AutoItX3Lib).
As per my application I am crawling different client websites through stimulating IE and Firefox browser.
I am facing popup problem , because during crawling few popups come at any time and they hang the application in between until I close appropriate button(like OK, Cancel etc).
I have managed few well known popups with below code.
using System.Text;
using AutoItX3Lib;
using System.Windows.Forms;
namespace PopupController
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void popupcontr_Tick(object sender, EventArgs e)
{
AutoItX3Class aX3C;
try
{
aX3C = new AutoItX3Class();
aX3C.AutoItSetOption("WinTitleMatchMode", 4);
/////////////////////
//// TITLE PART : when there is proper title...
//http://code.google.com/p/scite-ru/source/browse/trunk/pack/api/au3.api
///////////////////
if (1 == aX3C.WinExists("[REGEXPTITLE:.*Microsoft Internet Explorer.*]", ""))
{
aX3C.WinActivate("[REGEXPTITLE:.*Microsoft Internet Explorer.*]", "");
aX3C.WinClose("[REGEXPTITLE:.*Microsoft Internet Explorer.*]", "");
}
if (1 == aX3C.WinExists("Opening favicon.ico", ""))
{
aX3C.WinActivate("Opening favicon.ico", "");
aX3C.WinClose("Opening favicon.ico", "");
}
if (1 == aX3C.WinExists("[REGEXPTITLE:Security Warning]", ""))
{
if (aX3C.WinGetText("[REGEXPTITLE:Security Warning]", "").Length != 0)
{
aX3C.WinActivate("[REGEXPTITLE:Security Warning]", "");
aX3C.WinClose("[REGEXPTITLE:Security Warning]", "");
}
}
if (1 == aX3C.WinExists("[REGEXPTITLE:Security Alert]", ""))
{
if (aX3C.WinGetText("[REGEXPTITLE:Security Alert]", "").Length != 0)
{
aX3C.WinActivate("[REGEXPTITLE:Security Alert]", "");
aX3C.WinClose("[REGEXPTITLE:Security Alert]", "");
}
}
////////////////////////////////////////////////////////////////
// MESSAGE PART : when there are no title and just message only
/////////////////////////////////////////////////////////////////
if (1 == aX3C.WinExists("", "You have requested an encrypted page"))
{
string wintext = aX3C.WinGetText("", "You have requested an encrypted page");
if (wintext.Contains("You have requested an encrypted page") )
{
aX3C.WinActivate("", "You have requested an encrypted page");
aX3C.WinClose("", "You have requested an encrypted page");
}
}
if (1 == aX3C.WinExists("", "Firefox can't find the server at"))
{
string wintext = aX3C.WinGetText("", "Firefox can't find the server at");
if (wintext.Contains("Firefox can't find the server at"))
{
aX3C.WinActivate("", "Firefox can't find the server at");
aX3C.WinClose("", "Firefox can't find the server at");
}
}
if (1 == aX3C.WinExists("", "The certificate is only valid for"))
{
string wintext = aX3C.WinGetText("", "The certificate is only valid for");
if (wintext.Contains("The certificate is only valid for"))
{
aX3C.WinActivate("", "The certificate is only valid for");
aX3C.WinClose("", "The certificate is only valid for");
}
}
if (1 == aX3C.WinExists("", "The certificate is not trusted"))
{
string wintext = aX3C.WinGetText("", "The certificate is not trusted");
if (wintext.Contains("The certificate is not trusted"))
{
aX3C.WinActivate("", "The certificate is not trusted");
aX3C.WinClose("", "The certificate is not trusted");
}
}
For this I am collecting all different messages and title from AUTOIT and incorporate it in my coding and update my program everyday.
But it seems that it is endless process as I don’t know what kind of popups are there on Internet.
Questions
Is there any code to close all IE popups if title is available or not available???
How can I click ok , cancel button through program with minimum coding???
Guys Please help me as I am running out of time.
Thanks,
Chetan J.