public void SwitchWindowTest() { driver.Url = "http://book.theautomatedtester.co.uk/"; IWebElement chapter1Link = driver.FindElement(By.LinkText("Chapter1")); chapter1Link.Click(); IWebElement anotherWindowLink = driver.FindElement(By.Id("multiplewindow")); string window1 = driver.CurrentWindowHandle; Console.WriteLine(window1); anotherWindowLink.Click(); WaitTool.WaitForElementPresent(driver, By.Id("closepopup"), 5); string window2 = driver.WindowHandles[1]; driver.SwitchTo().Window(window2); IWebElement anotherWindowClose = driver.FindElement(By.Id("closepopup")); anotherWindowClose.Click(); driver.SwitchTo().Window(window1); IWebElement homePageLink = driver.FindElement(By.LinkText("Home Page")); homePageLink.Click(); }
//[Ignore("Ignore a test")] public void testAjax() { driver.Url = "https://www.w3schools.com/xml/ajax_intro.asp"; string originalText = driver.FindElement(By.CssSelector("div#demo>h2")).Text; driver.FindElement(By.CssSelector("div#demo>button")).Click(); bool isReady = WaitTool.WaitForJqueryProcessing(driver, 15); if (isReady) { string afterAJAX_Call_Text = driver.FindElement(By.CssSelector("div#demo>h1")).Text; Console.WriteLine("Before " + originalText); Assert.False(originalText.Equals(afterAJAX_Call_Text, StringComparison.OrdinalIgnoreCase)); Console.WriteLine("After " + afterAJAX_Call_Text); } else { Assert.Fail("Verify Failed: AJAX XMLHttpRequest is not ready"); } }