private static void doConfirm(WebDriver driver, String linkText) throws InterruptedException {
    	Set<String> originalWindows = new HashSet<String>(driver.getWindowHandles());
    	String currentWin = driver.getWindowHandle();
        
		driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
		(new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
			public Boolean apply(WebDriver d) {
				if (!d.findElements(By.cssSelector("input[type='button'][value^='нT{']")).isEmpty()) {
					return true;
				} 
				else if (!d.findElements(By.cssSelector("input[type='button'][disabled]")).isEmpty()) {
					return true;
				}
				else {
					return false;
				}
			}
		});
		
    	List<WebElement> confirmButtons = driver.findElements(By.cssSelector("input[type='button'][value^='нT{']"));
		driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        
        if(confirmButtons.isEmpty()) {
        	System.err.println("No button found: "+linkText);
        	return;
        }
        else if(confirmButtons.size() > 1) {
        	System.err.println("Multiple buttons found: "+linkText);
        	return;
        }
        
        confirmButtons.get(0).click();
        
        while(driver.getWindowHandles().size() != originalWindows.size()+1) {
        	try {
				Thread.sleep(500);
			} catch (InterruptedException e) {
				break;
			}
        }
        
        String newWin = null;
        for(String handle: driver.getWindowHandles()) {
        	if(!originalWindows.contains(handle)) {
            	// New window found
            	newWin = handle;
            	break;
        	}
        }
        
        if(newWin == null) {
        	System.err.println("No new window found after clicking the button: "+linkText);
        }
        
        driver.switchTo().window(newWin);
        
        driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
        if(!driver.findElements(By.id("overridelink")).isEmpty()) {
        	driver.navigate().to("javascript:document.getElementById('overridelink').click()");
        }
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        
        driver.findElement(By.cssSelector("input[type='submit'][value='T{']")).click();
//        ((JavascriptExecutor)driver).executeScript("document.getElementById('check').action += '?kind=save'");
//        driver.findElement(By.cssSelector("input[type='submit'][value='T{']")).submit();
        driver.switchTo().alert().accept();
        driver.switchTo().window(currentWin);
        System.out.println("Confirmed: "+linkText);
	}