本文整理汇总了C#中IWebDriver.GetWindowHandle方法的典型用法代码示例。如果您正苦于以下问题:C# IWebDriver.GetWindowHandle方法的具体用法?C# IWebDriver.GetWindowHandle怎么用?C# IWebDriver.GetWindowHandle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IWebDriver
的用法示例。
在下文中一共展示了IWebDriver.GetWindowHandle方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleSeleneseCommand
protected override object HandleSeleneseCommand(IWebDriver driver, string locator, string value)
{
string waitMessage = string.Format(CultureInfo.InvariantCulture, "Timed out waiting for {0}. Waited {1}", locator, value);
string current = driver.GetWindowHandle();
PopupWaiter waiter = new PopupWaiter(driver, locator, windows);
if (!string.IsNullOrEmpty(value))
{
long millis = long.Parse(value, CultureInfo.InvariantCulture);
waiter.Wait(waitMessage, millis);
}
else
{
waiter.Wait(waitMessage);
}
return null;
}
示例2: 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");
}
示例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);
attributes.Add(driver.Title);
}
driver.SwitchTo().Window(current);
return attributes.ToArray();
}
示例4: 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();
}
示例5: SelectFrame
public void SelectFrame(IWebDriver driver, string locator)
{
if (locator == "relative=top")
{
driver.SwitchTo().DefaultContent();
lastFrame.Remove(driver.GetWindowHandle());
return;
}
try
{
lastFrame.Add(driver.GetWindowHandle(), locator);
driver.SwitchTo().Frame(locator);
}
catch (NoSuchFrameException e)
{
throw new SeleniumException(e.Message);
}
}
示例6: SelectWindow
public void SelectWindow(IWebDriver driver, string windowId)
{
if (windowId == "null")
{
driver.SwitchTo().Window(originalWindowHandle);
}
else if (windowId == "_blank")
{
SelectBlankWindow(driver);
}
else
{
if (windowId.StartsWith("title=", StringComparison.Ordinal))
{
SelectWindowWithTitle(driver, windowId.Substring("title=".Length));
return;
}
if (windowId.StartsWith("name=", StringComparison.Ordinal))
{
windowId = windowId.Substring("name=".Length);
}
try
{
driver.SwitchTo().Window(windowId);
}
catch (NoSuchWindowException)
{
SelectWindowWithTitle(driver, windowId);
}
}
if (lastFrame.ContainsKey(driver.GetWindowHandle()))
{
// If the frame has gone, fall back
try
{
SelectFrame(driver, lastFrame[driver.GetWindowHandle()]);
}
catch (SeleniumException)
{
lastFrame.Remove(driver.GetWindowHandle());
}
}
}
示例7: WindowSelector
public WindowSelector(IWebDriver driver)
{
originalWindowHandle = driver.GetWindowHandle();
}
示例8: 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);
}
}