本文整理汇总了C#中IWebDriver.GetWindowHandles方法的典型用法代码示例。如果您正苦于以下问题:C# IWebDriver.GetWindowHandles方法的具体用法?C# IWebDriver.GetWindowHandles怎么用?C# IWebDriver.GetWindowHandles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IWebDriver
的用法示例。
在下文中一共展示了IWebDriver.GetWindowHandles方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SelectBlankWindow
/**
* 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");
}
示例2: HandleSeleneseCommand
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();
}
示例3: HandleSeleneseCommand
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();
}
示例4: SelectWindowWithTitle
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);
}
}