I have used AutoIt to deal with an authentication popup that Selenium Webdriver was unable to send keys to. Now, after the AutoIT process, I can successfully log into the website but none of the code after the process appears to work. I think that the window may no longer be the focus of Selenium Webdriver.
Is there a way to get the window's handle/name before the authentication popup occurs and then use that after the process to refocus on the window?
Below is my current code:
using System;
using System.Diagnostics;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System.Linq;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Support.UI;
namespace Selenium
{
[TestClass]
public class UnitTest1
{
static IWebDriver driverGC;
public object ExpectedConditions { get; private set; }
[AssemblyInitialize]
public static void SetUp(TestContext context)
{
driverGC = new ChromeDriver(@"C:\Browser Drivers\Chrome");
}
[TestMethod]
public void TestGC()
{
string UserNameGC = "username@website";
try
{
driverGC.Navigate().GoToUrl("https://WEBSITE.com/");
**string parentWindow = driverGC.CurrentWindowHandle.ToString();**
driverGC.FindElement(By.Id("i0116")).SendKeys(UserNameGC);
driverGC.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
driverGC.FindElement(By.Id("idSIButton9")).Click();
Thread.Sleep(3000);
Process.Start(@"C:\AutoIT.exe");
Thread.Sleep(6000);
driverGC.SwitchTo().Window(parentWindow);
driverGC.FindElement(By.Id("search-reviewee")).SendKeys("John Smith");
Thread.Sleep(3000);
driverGC.FindElement(By.Id("searchbtn")).Click();
}
catch (Exception ex)
{
}
finally
{
driverGC.Dispose();
driverGC.Quit();
}
}
}
}
I have tried to use string parentWindow = driverGC.CurrentWindowHandle.ToString() to get the handle and then (after the process) driverGC.SwitchTo().Window(parentWindow); to return to the window.
EDIT: I am using Chrome Version 78.0.3904.108.
Thanks in advance.