Search code examples
c#seleniumfirefoxselenium-webdriverautoit

Selenium script fails after using Auto IT script to handle windows based pop up


I have a website that prompts for username and password through an Authentication Window pop-up. So, I relied on AutoIt to handle the pop-up and it works (enters the username and password).

Once credentials are validated, the homepage of my website opens up in a time gap of 10-15 seconds.

Here is what I am doing:

class Class1
{
FirefoxDriver d;
static void Main(string[] args)
        {
d = new FirefoxDriver();
d.Manage().Window.Maximize();
d.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(60);
d.Url = "www.example.com";
Process.Start(@"C:\Users\Documents\AutoIt Scripts\Authentication_FireFox.exe");

//Now I would like to click on an element on my homepage which I am not able to do bcos of some exceptions.

WebDriverWait wait = new WebDriverWait(d, TimeSpan.FromSeconds(30));
 wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(d.FindElement(By.XPath("//span[@title='Start search']"))));
d.FindElement(By.XPath("//span[@title='Start search']")).Click();
        }

Exception 1:

enter image description here

I then added Thread.Sleep(20000); after Process.Start(); which gave me a new Exception.

Exception 2: enter image description here

I am using FireFox v62 and latest firefox driver. AutoIT v 3.3.14.5

Can you please help me to find a resolution. Thanks in advance.


Solution

  • Made the web browser to throw an alert so that web browser gets into focus after handling the authentication pop-up.

    Code changes:

    Process.Start(@"C:\Users\Documents\AutoIt Scripts\Authentication_FireFox.exe");
    Thread.Sleep(30000);
    ((IJavaScriptExecutor)d).ExecuteScript("alert('Test')");
    d.SwitchTo().Alert().Accept();
    d.FindElement(By.XPath("//span[@title='Start search']")).Click(); // now this element is getting clicked.