Thursday, June 18, 2015

C# Selenium - Handling multiple windows


Multiple windows Handling

 driver.Navigate().GoToUrl("Sample1.html");
            driver.FindElement(By.LinkText("Visit W3Schools!")).Click();

            string BaseWindow = driver.CurrentWindowHandle;

            ReadOnlyCollection<string> handles = driver.WindowHandles;

            foreach (string handle in handles)
            {
                Boolean a = driver.SwitchTo().Window(handle).Url.Contains("http://www.w3schools.com/");
                if (a == true)
                {
                    driver = driver.SwitchTo().Window(handle);
                    break;
                }
            }

            driver.FindElement(By.LinkText("LEARN HTML")).Click();


            driver = driver.SwitchTo().Window(BaseWindow);


sample HTML

<!DOCTYPE html>
<html>
<body>

<iframe width="100%" height="300px" src="///F:/Yash/Selenium_Workshop_Training/htmls/Alerts.html" name="iframe_a"></iframe>
<p><a href="file:///F:/Yash/Selenium_Workshop_Training/htmls/Alerts.html" target="iframe_a">Selenium_Workshop_Training</a></p>

<p>When the target of a link matches the name of an iframe, the link will open in the iframe.</p>
<a href="http://www.w3schools.com/" target="_blank">Visit W3Schools!</a>
</body>
</html>


1 comment:

  1. Are you trying to make cash from your visitors by running popunder ads?
    In case you are, did you try using Propeller Ads?

    ReplyDelete