Click here to Skip to main content
15,890,947 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am using selenium c# code to manage a web-page. I have managed to open a web-page in firefox login to the web-page and open a child window in this web-page.
But I can not control the child window inside this web page.

I tried to use
C#
PopupWindowFinder
code:
C#
finder = new PopupWindowFinder(driver,timeout,sleepInterval);

            try {
                popUpWindow = finder.Click(driver.FindElement(By.XPath("//li[@class='quicklink icHumanResources']")));
            }
            catch (WebDriverException)
            {
                System.Threading.Thread.Sleep(10);
            }
            driver.SwitchTo().Window(popUpWindow);

But it does not work.

What I have tried:

C#
driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("https://WEB-ADDRESS/");

        

            IWebElement userName = driver.FindElement(By.XPath("//input[@class='LoginIputField focus']"));
            IWebElement password = driver.FindElement(By.Id("Engine_LoginScreen_txtPassword"));
            IWebElement loginButton = driver.FindElement(By.Id("Engine_LoginScreen_btnSubmit"));
            userName.SendKeys("XXXXXXXXXXXX");
            password.SendKeys("XXXXXXXXXXXXXXXXXXXXX");
            loginButton.Click();
           
           
             System.Threading.Thread.Sleep(20000);

            
            ITakesScreenshot ssdriver = driver as ITakesScreenshot;
            Screenshot screenshot = ssdriver.GetScreenshot();
            string timestamp = DateTime.Now.ToString("yyyy-MM-dd-hhmmss");
            screenshot.SaveAsFile("D:\\SLIKA" + @"\Exception-"+timestamp+".png", System.Drawing.Imaging.ImageFormat.Png);


            string currentHandle = driver.CurrentWindowHandle;

            System.Threading.Thread.Sleep(20000);

            TimeSpan timeout = new TimeSpan(0, 1, 0);
            TimeSpan sleepInterval = new TimeSpan(0, 1, 0);

            finder = new PopupWindowFinder(driver,timeout,sleepInterval);

            try {
                popUpWindow = finder.Click(driver.FindElement(By.XPath("//li[@class='quicklink icHumanResources']")));
            }
            catch (WebDriverException)
            {
                System.Threading.Thread.Sleep(10);
            }
           driver.SwitchTo().Window(popUpWindow);
Posted
Updated 15-Feb-17 2:45am
Comments
Andira Muttakim 24-Nov-16 3:56am    
Have you tried driver.SwitchTo().Frame(yourFrame)?
And what version of Selenium and Firefox you are using?

1 solution

Hi,

It sounds as though rather than use a window using a switchto frame could be needed in this case. If the window is within the webpage usually these are iframes or alerts. In my experience this is usually dealt with by the SwitchTo().Frame API method, I normally supply the iframe title to switch focus. I hope this is resolved and is of some help. Let me know if not and we can work on this I'm sure as deal with multiple windows / iframes / popups daily across my QA platform and they're interesting to work with,

C#
driver.SwitchTo().Frame(<This has 3 overrides>);


Cheers
Sean
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900