当前位置: 首页>>代码示例>>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;未经允许,请勿转载。