/** * Selects the only <code>_blank</code> window. A window open with * <code>target='_blank'</code> will have a <code>window.name = null</code>. * <p/> * <p>This method assumes that there will only be one single * <code>_blank</code> window and selects the first one with no name. * Therefore if for any reasons there are multiple windows with * <code>window.name = null</code> the first found one will be selected. * <p/> * <p>If none of the windows have <code>window.name = null</code> the last * selected one will be re-selected and a {@link SeleniumException} will * be thrown. * * @throws NoSuchWindowException if no window with * <code>window.name = null</code> is found. */ public void SelectBlankWindow(IWebDriver driver) { string current = driver.GetWindowHandle(); // Find the first window without a "name" attribute ReadOnlyCollection<string> handles = driver.GetWindowHandles(); foreach (string handle in handles) { // the original window will never be a _blank window, so don't even look at it // this is also important to skip, because the original/root window won't have // a name either, so if we didn't know better we might think it's a _blank popup! if (handle == originalWindowHandle) { continue; } driver.SwitchTo().Window(handle); string value = ((IJavaScriptExecutor)driver).ExecuteScript("return window.name;").ToString(); if (string.IsNullOrEmpty(value)) { // We found it! return; } } // We couldn't find it driver.SwitchTo().Window(current); throw new SeleniumException("Unable to select window _blank"); }
/// <summary> /// Selects the only <code>_blank</code> window. A window open with /// <code>target='_blank'</code> will have a <code>window.name = null</code>. /// </summary> /// <param name="driver">The driver to use to select the window.</param> /// <remarks> /// <para>This method assumes that there will only be one single /// <code>_blank</code> window and selects the first one with no name. /// Therefore if for any reasons there are multiple windows with /// <code>window.name = null</code> the first found one will be selected. /// </para> /// <para>If none of the windows have <code>window.name = null</code> the last /// selected one will be re-selected and a <see cref="SeleniumException"/> will /// be thrown. /// </para> /// </remarks> public void SelectBlankWindow(IWebDriver driver) { string current = driver.GetWindowHandle(); // Find the first window without a "name" attribute ReadOnlyCollection <string> handles = driver.GetWindowHandles(); foreach (string handle in handles) { // the original window will never be a _blank window, so don't even look at it // this is also important to skip, because the original/root window won't have // a name either, so if we didn't know better we might think it's a _blank popup! if (handle == this.originalWindowHandle) { continue; } driver.SwitchTo().Window(handle); string value = ((IJavaScriptExecutor)driver).ExecuteScript("return window.name;").ToString(); if (string.IsNullOrEmpty(value)) { // We found it! return; } } // We couldn't find it driver.SwitchTo().Window(current); throw new SeleniumException("Unable to select window _blank"); }
protected override object HandleSeleneseCommand(IWebDriver driver, string locator, string value) { string current = driver.GetWindowHandle(); List<string> attributes = new List<string>(); foreach (string handle in driver.GetWindowHandles()) { driver.SwitchTo().Window(handle); attributes.Add(driver.Title); } driver.SwitchTo().Window(current); return attributes.ToArray(); }
protected override object HandleSeleneseCommand(IWebDriver driver, string locator, string value) { string current = driver.GetWindowHandle(); List <string> attributes = new List <string>(); foreach (string handle in driver.GetWindowHandles()) { driver.SwitchTo().Window(handle); attributes.Add(driver.Title); } driver.SwitchTo().Window(current); return(attributes.ToArray()); }
protected override object HandleSeleneseCommand(IWebDriver driver, string locator, string value) { string current = driver.GetWindowHandle(); List<string> attributes = new List<string>(); foreach (string handle in driver.GetWindowHandles()) { driver.SwitchTo().Window(handle); string attributeValue = (string)((IJavaScriptExecutor)driver).ExecuteScript("return '' + window[arguments[0]];", value); attributes.Add(attributeValue); } driver.SwitchTo().Window(current); return attributes.ToArray(); }
protected override object HandleSeleneseCommand(IWebDriver driver, string locator, string value) { string current = driver.GetWindowHandle(); List <string> attributes = new List <string>(); foreach (string handle in driver.GetWindowHandles()) { driver.SwitchTo().Window(handle); string attributeValue = (string)((IJavaScriptExecutor)driver).ExecuteScript("return '' + window[arguments[0]];", value); attributes.Add(attributeValue); } driver.SwitchTo().Window(current); return(attributes.ToArray()); }
private static void SelectWindowWithTitle(IWebDriver driver, string title) { bool windowSuccessfullySwitched = false; string current = driver.GetWindowHandle(); foreach (string handle in driver.GetWindowHandles()) { driver.SwitchTo().Window(handle); if (title == driver.Title) { windowSuccessfullySwitched = true; break; } } if (!windowSuccessfullySwitched) { driver.SwitchTo().Window(current); throw new SeleniumException("Unable to select window with title: " + title); } }