locked
Opening multiple windows(without clicking any link in existing window) in selenium webdriver c# RRS feed

  • Question

  • Hi All,

    I am trying to compare 2 webpages using selenium webdriver c#. We are loading the page, waiting for some millisec and then reading the text. The same i am doing for the 2nd page. Below is the code .

    Here waiting period is double as i am waiting for pages to load one by one

    WebDriver.Navigate().GoToUrl("www.abc.com");

    //Wait for some time

    string string1 = TestDriver.FindElement(By.TagName("body")).Text;

    WebDriver.Navigate().GoToUrl("www.xyz.com");

    //Wait for some time

    string string2 = TestDriver.FindElement(By.TagName("body")).Text;

    if(string1==string2)

    {}

    else

    {}

    Now i want to open 2 windows back to back and load the url, read the text switching the pages and compare. So that i can save the milliseconds wait period in all my test cases.

    I could see some sample where new window is opened by clicking some link in the existing window and the window swtiching is handled. But i want to open the new window thrown code itself.

    Thanks

    Thursday, October 27, 2016 6:55 AM

All replies

  • Hi Prahalnathan,

    I think you could use Back and Forward function to implement switch between two pages. Just as the following codes:

    driver.Navigate().Back();
    
    driver.Navigate().Forward();
    

    Sincerely,

    Oscar


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, October 27, 2016 8:10 AM
  • Hi Oscar,

    For switching i can use windowhandle also. But i dont know how to open a new window from code without clicking an link

    Thursday, October 27, 2016 9:03 AM
  • Hi Prahalnathan,

    I think we could use the hot key like the following code.

    driver.FindElement(
    
    
    By.TagName("body")).SendKeys(OpenQA.Selenium.Keys.Control + "t");
    But this code only works at the beginning of opening browser in my side in IE.

    Sincerely,

    Oscar


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.



    • Edited by Oscar_Wu Thursday, October 27, 2016 9:09 AM
    Thursday, October 27, 2016 9:07 AM
  • Thanks Oscar. Will try this and get back. but i need for chrome. Also will this open new window or tab?
    Tuesday, November 1, 2016 8:56 AM
  • Hi Prahalnathan,

    Please use this code to open a new tag in Chrome.

    driver.ExecuteJavaScript("window.open()");

    If a reply that help you resolved your issue, would you please mark it as answer, which could help others who encountered the same issue as yours. If not, please feel free to let me know, thank you very much.

    Sincerely,

    Oscar


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    • Edited by Oscar_Wu Wednesday, November 2, 2016 2:35 AM
    Tuesday, November 1, 2016 10:06 AM