本文整理汇总了Java中org.openqa.selenium.WebDriver.getWindowHandle方法的典型用法代码示例。如果您正苦于以下问题:Java WebDriver.getWindowHandle方法的具体用法?Java WebDriver.getWindowHandle怎么用?Java WebDriver.getWindowHandle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openqa.selenium.WebDriver
的用法示例。
在下文中一共展示了WebDriver.getWindowHandle方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: closeWinByUrlStartWith
import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
/**
* 关闭url以指定字符串开头的window
* @param phoenix 引擎
* @param params 参数
*/
public static void closeWinByUrlStartWith(Phoenix phoenix, String[] params)
{
String startWith = params[0];
WebDriver driver = phoenix.getEngine().getDriver();
Set<String> handles = driver.getWindowHandles();
Iterator<String> handleIt = handles.iterator();
String currentHandle = driver.getWindowHandle();
while(handleIt.hasNext())
{
String handle = handleIt.next();
driver.switchTo().window(handle);
if(driver.getCurrentUrl().startsWith(startWith))
{
driver.close();
break;
}
}
driver.switchTo().window(currentHandle);
}
示例2: switchToNewWindow
import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
@Override
public void switchToNewWindow() {
WebDriver driver = webPage.getDriver();
baseWindowHandle = driver.getWindowHandle();
Thucydides.getCurrentSession().put("baseWindowHandle",
baseWindowHandle);
Set<String> openedWindows = driver.getWindowHandles();
String newWindow = null;
if (openedWindows.size() > 1 && openedWindows.remove
(baseWindowHandle)) {
Iterator<String> openedWindowsIterator = openedWindows.iterator();
newWindow = openedWindowsIterator.next();
} else {
int timeout = getSatisfyWebProperties().getSatisfyWait();
WebDriverWait wait = new WebDriverWait(driver, timeout);
newWindow = wait.until(anyWindowOtherThan(openedWindows));
}
driver.switchTo().window(newWindow);
}
示例3: AbstractHtmlEngine
import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
public AbstractHtmlEngine( UiDriver uiDriver,
AbstractElementsFactory elementsFactory ) {
super(uiDriver, elementsFactory);
AbstractHtmlDriver htmlDriver = (AbstractHtmlDriver) uiDriver;
webDriver = (WebDriver) htmlDriver.getInternalObject(InternalObjectsEnum.WebDriver.name());
mainWindowHandle = webDriver.getWindowHandle();
}
示例4: switchToChildWindow
import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
/**
* Switch to child window.
*
* @param driver the driver
* @param childPagetitle the child pagetitle
*/
public static void switchToChildWindow(WebDriver driver, String childPagetitle) {
Set<String> allWin = driver.getWindowHandles();
String parentWindow = driver.getWindowHandle();
for (String childWindow : allWin) {
if (!childWindow.equalsIgnoreCase(parentWindow)) {
if (driver.switchTo().window(childWindow).getTitle().equalsIgnoreCase(childPagetitle)) {
break;
}
}
}
}
示例5: changeWindow
import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
public static void changeWindow(WebDriver driver){
// 获取当前页面句柄
String handle = driver.getWindowHandle();
// 获取所有页面的句柄,并循环判断不是当前的句柄,就做选取switchTo()
for (String handles : driver.getWindowHandles()) {
if (handles.equals(handle))
continue;
driver.switchTo().window(handles);
}
}