0

I perform such steps in an automated test case:

  • Login to an application
  • Switch to a frame with title "Main Menu" (example)
  • Select and click desired element from: "Main Menu > Sub Menu 1> Sub Menu 2 > Search": When "Search" is clicked then a new child window with it's own url is opened. The "Search" click also changes frame in the background, it triggers a page reload and so "Main Menu" changes into "Detailed Menu".
  • When some id is given on child window and search button on child window is clicked, then child window will be closed and "Detailed Menu" will be updated with information for this particular id.

Problem:

When IE driver (version 3.14.0.0) clicks search button from "Main Menu > Sub Menu 1> Sub Menu 2 > Search" then child window which is opened does not contain all information. It looks like it's ok, but after looking at it's properties the url indicates that it's a blank html page. Because it's blank/disabled I cannot switch to it, find any element or click any button.

I managed to do above test steps with ChromeDriver, but the test must be executed using IE driver (application requirements).

I also tried setting capabilities of IE driver as stated in: How can I start InternetExplorerDriver using Selenium WebDriver but I can't modify any Internet Explorer security options, because these options are disabled.

I noticed that when I use the following code after driver performs "Main Menu > Sub Menu 1> Sub Menu 2 > Search":

  foreach (var process in Process.GetProcessesByName("IEDriverServer"))
        {
            process.Kill();

        }

Then child window becomes fully operational, but of course driver session is over, so I can't proceed with later steps anyway.

Question:

Is there a way to pause driver's processes after it performs click, wait for child window to be fully loaded, then resume processes so it can switch to a child window etc? If not is there a way to attach this window to current browser session?

Mina
  • 75
  • 10

1 Answers1

0

I suggest you to check the Explicit Wait.

Explicit waits are available to Selenium clients for imperative, procedural languages. They allow your code to halt program execution, or freeze the thread, until the condition you pass it resolves. The condition is called with a certain frequency until the timeout of the wait is elapsed. This means that for as long as the condition returns a falsy value, it will keep trying and waiting.

With the helps of that you can try to pause the code until any specific control on that window get visible.

Sample C# example:

 WebDriverWait wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(4));

            // Test the autocomplete response - Explicit Wait
            IWebElement autocomplete = wait.Until(x => x.FindElement(By.ClassName("ac-row-110457")));

Another example:

// The timespan determines how long to wait for any 'condition' to return a value
// If it is exceeded an exception is thrown.
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5.0));

// Set the 'condition' as an anonymous function returning a boolean
wait.Until<Boolean>(delegate(IWebDriver d)
{
    // Check if our global variable is initialized by running a little JS
    return (Boolean)((IJavaScriptExecutor)d).ExecuteScript("return typeof(window.TestReady) !== 'undefined' && window.TestReady === true");
});

References:

(1) How I can check whether a page is loaded completely or not in web driver?

(2) Explicit wait

(3) Selenium Webdriver - Wait for an element to load

Deepak-MSFT
  • 10,379
  • 1
  • 12
  • 19