本文整理匯總了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);
}
}