Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 99048

The first loop for printing driver.WindowHandles giving me 2 window handles when only one window is opened

$
0
0

for getting the number of window handles after opening one window and after opening one more window.the first for loop is giving me 2 window handles instead of 1,when only 1 window is opened.whereas the second loop is giving me 2 window handles which is after opening the second window which is correct.

public class BaseTest    {        public IWebDriver driver;        [OneTimeSetUp]        public void Setup()        {            driver = new ChromeDriver();            driver.Manage().Window.Maximize();        } 
       [OneTimeTearDown]         public void TearDown()         {             driver.Quit();            extent.Flush();        }
     }
[TestClass]    public class Tests :BaseTest    {        BaseTest base1=new BaseTest();
 [Test]        public void Test6()        {            HTMLtestPage hTMLtestPage= new HTMLtestPage(driver);            //hTMLtestPage.searchSome();            hTMLtestPage.htmlres();        }
      }
public class HTMLtestPage    {   public void htmlres()        {       driver.Url = "https://www.google.com/";    Console.WriteLine("initial no of windhandls");    List<String> list = new List<String>(driver.WindowHandles);    foreach (var x in list)    {    Console.WriteLine(x);    }    Thread.Sleep(1000);    driver.SwitchTo().NewWindow(WindowType.Window);    driver.Url = "https://www.w3schools.com/Xml/xpath_syntax.asp";    Console.WriteLine(driver.CurrentWindowHandle);    Thread.Sleep(1000);    List<String> listn = new List<String>(driver.WindowHandles);    Console.WriteLine("printing in for loop");    foreach (var y in listn){    Console.WriteLine(y);    }}

}

Please Click this link for Results image in standard output


Viewing all articles
Browse latest Browse all 99048

Latest Images

Trending Articles



Latest Images