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


Java WebDriver.close方法代碼示例

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


在下文中一共展示了WebDriver.close方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: closeOthers

import org.openqa.selenium.WebDriver; //導入方法依賴的package包/類
@Override
public void closeOthers()
{
	String currentTitle = getTitle();
	String currentWinHandle = engine.getDriver().getWindowHandle();
	
	for(String winHandle : engine.getDriver().getWindowHandles())
	{
		WebDriver itemDrive = engine.getDriver().switchTo().window(winHandle);
		if(!itemDrive.getTitle().equals(currentTitle))
		{
			itemDrive.close();
		}
	}
	
	engine.getDriver().switchTo().window(currentWinHandle);
}
 
開發者ID:LinuxSuRen,項目名稱:phoenix.webui.framework,代碼行數:18,代碼來源:WebPage.java

示例2: 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

示例3: main

import org.openqa.selenium.WebDriver; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception{
    //配置ChromeDiver
    System.getProperties().setProperty("webdriver.chrome.driver", "chromedriver.exe");
    //開啟新WebDriver進程
    WebDriver webDriver = new ChromeDriver();
    //全局隱式等待
    webDriver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
    //設定網址
    webDriver.get("https://passport.weibo.cn/signin/login?entry=mweibo&res=wel&wm=3349&r=http%3A%2F%2Fm.weibo.cn%2F");
    //顯示等待控製對象
    WebDriverWait webDriverWait=new WebDriverWait(webDriver,10);
    //等待輸入框可用後輸入賬號密碼
    webDriverWait.until(ExpectedConditions.elementToBeClickable(By.id("loginName"))).sendKeys(args[0]);
    webDriverWait.until(ExpectedConditions.elementToBeClickable(By.id("loginPassword"))).sendKeys(args[1]);
    //點擊登錄
    webDriver.findElement(By.id("loginAction")).click();
    //等待2秒用於頁麵加載,保證Cookie響應全部獲取。
    sleep(2000);
    //獲取Cookie並打印
    Set<Cookie> cookies=webDriver.manage().getCookies();
    Iterator iterator=cookies.iterator();
    while (iterator.hasNext()){
        System.out.println(iterator.next().toString());
    }
    //關閉WebDriver,否則並不自動關閉
    webDriver.close();
}
 
開發者ID:CieloSun,項目名稱:FashionSpider,代碼行數:28,代碼來源:WeiboLoginAndGetCookie.java

示例4: testSelenium

import org.openqa.selenium.WebDriver; //導入方法依賴的package包/類
public static void testSelenium() throws Exception {
    System.getProperties().setProperty("webdriver.chrome.driver", "chromedriver.exe");
    WebDriver webDriver = new ChromeDriver();
    webDriver.get("http://huaban.com/");
    Thread.sleep(5000);
    WebElement webElement = webDriver.findElement(By.xpath("/html"));
    System.out.println(webElement.getAttribute("outerHTML"));
    webDriver.close();
}
 
開發者ID:CieloSun,項目名稱:FashionSpider,代碼行數:10,代碼來源:Test.java

示例5: closeDrivers

import org.openqa.selenium.WebDriver; //導入方法依賴的package包/類
/**
 * Quits all of the web drivers in the list.
 */
private void closeDrivers() {
  for (WebDriver webDriver : this.webDriverList)
    try {
      // Open about:config in case of fennec (Firefox for Android) and close.
      if (((RemoteWebDriver) webDriver).getCapabilities().getBrowserName().equalsIgnoreCase("fennec")) {
        webDriver.get("about:config");
        webDriver.close();
      } else {
        webDriver.quit();
      }
    } catch (Exception e) {
      logger.error("closing driver:", e);
    }
}
 
開發者ID:webrtc,項目名稱:KITE,代碼行數:18,代碼來源:TestManager.java

示例6: main

import org.openqa.selenium.WebDriver; //導入方法依賴的package包/類
public static void main(String[] args) {

        setupDriverExecutable("chromedriver", "webdriver.chrome.driver");
        WebDriver driver =  new ChromeDriver();

        try {
            crawl(driver);
        } catch (Exception e){
            System.out.println("ERROR: "+e.getMessage());
            e.printStackTrace();
        }

        driver.close();
    }
 
開發者ID:arcuri82,項目名稱:testing_security_development_enterprise_systems,代碼行數:15,代碼來源:GitCrawler.java

示例7: finishTest

import org.openqa.selenium.WebDriver; //導入方法依賴的package包/類
public static void finishTest(WebDriver driver){
	if (System.getenv().get("TRAVIS_JOB_NUMBER") != null) {
		SauceREST sauceRest = new SauceREST(System.getenv().get("SAUCE_USERNAME"), System.getenv().get("SAUCE_ACCESS_KEY"));
		sauceRest.jobPassed((((RemoteWebDriver) driver).getSessionId()).toString());
	}

	driver.close();
	driver.quit();
}
 
開發者ID:Arquisoft,項目名稱:dashboard1b,代碼行數:10,代碼來源:SeleniumUtils.java

示例8: handleNewSnap

import org.openqa.selenium.WebDriver; //導入方法依賴的package包/類
private byte[] handleNewSnap(final String id, final String size) throws IOException, TimeoutException {

        final EmbeddableData data = getAvailablePlotList()
                .stream()
                .filter(x -> x.getIdentifier().equals(id))
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("The request " + id + " is not available"));
        final WebDriver webDriver = webDriver();
        try (Jedis jedis = jedisPool.getResource()) {
            final Page pageHandler = fromId(id);

            final ScreenShotService.Builder builder = new ScreenShotService
                    .Builder()
                    .setPageHandler(pageHandler)
                    .jedis(jedis)
                    .id(id)
                    .webDriver(webDriver)
                    .plotUrl(new URL(data.getIframeUrl()))
                    .ttl(Integer.parseInt(properties.getProperty("caching.ttl")))
                    .timeout(30);

            if (!size.equals(ORIGINAL_SIZE))
                builder.geometry(Geometry.fromString(size));

            final ScreenShotService service = builder.build();
            service.perform();
            return service.fetch(id, size);
        } finally {
            try {
                if (webDriver != null) {
                    webDriver.close();
                    webDriver.quit();
                }
            } catch (Exception ex) {
                //Ignored
            }
        }


    }
 
開發者ID:italia,項目名稱:daf-cacher,代碼行數:41,代碼來源:ApiService.java

示例9: 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


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