getWindowHandles()。size()返回不正确的值

时间:2016-11-04 13:00:07

标签: selenium-webdriver

我正在使用Windows 8,IE 11和任何版本的IEDriverSever。

getWindowHandles()。size()返回不正确的大小。如果 打开窗口的数量是2,getWindowHandles()。size()返回1。

正如所建议的那样,我附上了我的代码。

public class TIEBrowser {
	
	public static void main(String[] args) throws InterruptedException {
		
		
		DesiredCapabilities dc = new DesiredCapabilities();
		dc.setCapability(InternetExplorerDriver.
				  INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);

			
		System.setProperty("webdriver.ie.driver", "C:\\Selenium\\IEDriverServer\\IEDriverServer.exe");
		WebDriver driver = new InternetExplorerDriver(dc);
				
		String baseUrl = "http://10.72.139.159:8080/krsnsys/";
                
		driver.navigate().to(baseUrl);
		
		driver.manage().window().maximize();
        
        System.out.println(driver.getTitle()+" -1- ");
        
        WebElement myElement = driver.findElement(By.id("username-id"));
        myElement.sendKeys("silk1");
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.findElement(By.name("login")).click();
                
        driver.switchTo();
                
        String NewInteraction = "html/body/div[1]/div[5]/div[2]/div/div/div[5]/fieldset/div/div/div/div/div[1]/fieldset/div/a[1]/div/img";
        WebElement link = driver.findElement(By.xpath(NewInteraction));
        
        WebDriverWait wait = new WebDriverWait(driver, 120);// 1 minute 
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(NewInteraction)));
                       
        System.out.println(driver.getTitle()+" -2- ");
        System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++");
        
        String handle= driver.getWindowHandle();
        System.out.println(handle);
        link.click();
               
        System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++");
        
        Thread.sleep(4000);
        System.out.println(handle);
        
        Set<String> handles =  driver.getWindowHandles();
        **System.out.println(handles.size());**
        for(String windowHandle  : handles)
            {
            System.out.println(windowHandle);
     	   if(!windowHandle.equals(handle))
               {
               driver.switchTo().window(windowHandle);
               System.out.println(windowHandle);
               }
            }
               
           System.out.println(handle);
           driver.manage().window().maximize();
           Thread.sleep(2000);

0 个答案:

没有答案