當前位置: 首頁>>代碼示例>>Java>>正文


Java WebDriver.getWindowHandles方法代碼示例

本文整理匯總了Java中org.openqa.selenium.WebDriver.getWindowHandles方法的典型用法代碼示例。如果您正苦於以下問題:Java WebDriver.getWindowHandles方法的具體用法?Java WebDriver.getWindowHandles怎麽用?Java WebDriver.getWindowHandles使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.openqa.selenium.WebDriver的用法示例。


在下文中一共展示了WebDriver.getWindowHandles方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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);
}
 
開發者ID:LinuxSuRen,項目名稱:phoenix.webui.framework,代碼行數:29,代碼來源:EngineInvoker.java

示例2: newWindowOpens

import org.openqa.selenium.WebDriver; //導入方法依賴的package包/類
/**
 * @param currentHandles
 *            is list of opened windows.
 * @return a string with new Window Opens (GUID)
 */
public static ExpectedCondition<String> newWindowOpens(final Set<String> currentHandles) {
    return new ExpectedCondition<String>() {

        /**
         * {@inheritDoc}
         */
        @Override
        public String apply(@Nullable WebDriver driver) {
            if (driver != null && !currentHandles.equals(driver.getWindowHandles())) {
                for (String s : driver.getWindowHandles()) {
                    if (!currentHandles.contains(s)) {
                        return s;
                    }
                }
            }
            return null;
        }
    };
}
 
開發者ID:NoraUi,項目名稱:NoraUi,代碼行數:25,代碼來源:WindowManager.java

示例3: 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);
}
 
開發者ID:tapack,項目名稱:satisfy,代碼行數:20,代碼來源:BasePageSteps.java

示例4: initIEDriver

import org.openqa.selenium.WebDriver; //導入方法依賴的package包/類
private WebDriver initIEDriver(String appURL) {
	System.out.println("Launching IE browser..");
	DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
	ieCapabilities.setJavascriptEnabled(true); 
	ieCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS,   
			true); 
	ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true); 
	ieCapabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING,true);         
	ieCapabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR,UnexpectedAlertBehaviour.DISMISS); //Accept unexpected alerts 
	ieCapabilities.setCapability("requireWindowFocus", true); 
	ieCapabilities.setCapability("enablePersistentHover", false); 
	ieCapabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
	
	WebDriver driver=new InternetExplorerDriver(ieCapabilities);
	driver.manage().deleteAllCookies();
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    for(String winHandle : driver.getWindowHandles()){
       driver =  driver.switchTo().window(winHandle);
    }
    driver.get(appURL);
	return new WebDriverProxy().protect(driver);
}
 
開發者ID:3pillarlabs,項目名稱:AutomationFrameworkTPG,代碼行數:23,代碼來源:DriverProperties.java

示例5: windowSwitch

import org.openqa.selenium.WebDriver; //導入方法依賴的package包/類
/**
 * window窗口切換
 * @param phoenix 引擎
 */
public static void windowSwitch(Phoenix phoenix)
{
	SeleniumEngine engine = phoenix.getEngine();
	WebDriver driver = engine.getDriver();
	Set<String> handlers = driver.getWindowHandles();
	Iterator<String> it = handlers.iterator();
	while(it.hasNext())
	{
		String name = it.next();
		
		driver.switchTo().window(name);
	}
}
 
開發者ID:LinuxSuRen,項目名稱:phoenix.webui.framework,代碼行數:18,代碼來源:EngineInvoker.java

示例6: anyWindowOtherThan

import org.openqa.selenium.WebDriver; //導入方法依賴的package包/類
private ExpectedCondition<String> anyWindowOtherThan(
        final Set<String> oldWindows) {
    return new ExpectedCondition<String>() {
        public String apply(WebDriver driver) {
            if (driver == null)
                throw new WebDriverException();
            Set<String> allWindows = driver.getWindowHandles();
            allWindows.removeAll(oldWindows);
            return allWindows.size() > 0 ? allWindows.iterator().next()
                    : null;
        }
    };
}
 
開發者ID:tapack,項目名稱:satisfy,代碼行數:14,代碼來源:BasePageSteps.java

示例7: 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;
			}
		}
	}
}
 
開發者ID:anilpandeykiet,項目名稱:POM_HYBRID_FRAMEOWRK,代碼行數:19,代碼來源:WebBrowser.java

示例8: returnToPool

import org.openqa.selenium.WebDriver; //導入方法依賴的package包/類
public void returnToPool(WebDriver webDriver) {
	if (shutdowned.get()) {
		webDriver.quit();
		webDriver = null;
	} else {
		Set<String> handles = webDriver.getWindowHandles();
		if (handles.size() > 1) {
			int index = 0;
			for (String handle : handles) {
				if (index == 0) {
					index++;
					continue;
				}
				WindowUtil.changeWindowTo(webDriver, handle);
				webDriver.close();
				index++;
			}
		}
		synchronized (shutdowned) {
			if(!shutdowned.get()){
				innerQueue.add(webDriver);
			}else{
				webDriver.quit();
				webDriver = null;
			}
		}
	}
}
 
開發者ID:xbynet,項目名稱:crawler,代碼行數:29,代碼來源:PhantomjsWebDriverPool.java

示例9: 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);
	}
}
 
開發者ID:xbynet,項目名稱:crawler,代碼行數:11,代碼來源:WindowUtil.java

示例10: changeWindowTo

import org.openqa.selenium.WebDriver; //導入方法依賴的package包/類
public static void changeWindowTo(WebDriver driver,String handle){
	for (String tmp : driver.getWindowHandles()) {
		if (tmp.equals(handle)){
			driver.switchTo().window(handle);
			break;
		}
	}
}
 
開發者ID:xbynet,項目名稱:crawler,代碼行數:9,代碼來源:WindowUtil.java

示例11: openNewTab

import org.openqa.selenium.WebDriver; //導入方法依賴的package包/類
/**
 * 打開一個新tab頁,返回該tab頁的windowhandle
 * @param driver
 * @param url
 * @return
 */
public static String openNewTab(WebDriver driver,String url){
	Set<String> strSet1=driver.getWindowHandles();
	((JavascriptExecutor)driver).executeScript("window.open('"+url+"','_blank');");
	sleep(1000);
	Set<String> strSet2=driver.getWindowHandles();
	for(String tmp:strSet2){
		if(!strSet1.contains(tmp)){
			return tmp;
		}
	}
	return null;
}
 
開發者ID:xbynet,項目名稱:crawler,代碼行數:19,代碼來源:WindowUtil.java


注:本文中的org.openqa.selenium.WebDriver.getWindowHandles方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。