2017-08-29 63 views
0

我使用Selenium來自動化一些測試。 WebDriver api getWindowHandle()總是返回2147483649。它實際上應該返回一個字母數字字符串,如{9e10f4f4-2da6-ef43-b463-1b0d576e7dae},通常每次測試運行時都會更改。但我總是得到2147483649。我使用Selenium 3.5.1和Firefox 55.0.2。Selenium WebDriver api getWindowHandles()總是返回2147483649

代碼重現發出─

的Java

public class SeleniumExample { 
    public static void main(String args[]){ 
     System.setProperty("webdriver.gecko.driver","/Users/raghavendr.kolisetty/Downloads/geckodriver"); 
     WebDriver driver = new FirefoxDriver(); 
     driver.manage().window().maximize(); 
     driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS); 
     driver.get("http://www.google.com"); 
     System.out.println("printing test handles "+driver.getWindowHandle()); 
    } 
} 

POM

<properties> 
    <selenium.java.version>3.5.1</selenium.java.version> 
</properties> 
<dependencies> 
    <dependency> 
     <groupId>org.seleniumhq.selenium</groupId> 
     <artifactId>selenium-firefox-driver</artifactId> 
     <version>${selenium.java.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.seleniumhq.selenium</groupId> 
     <artifactId>selenium-java</artifactId> 
     <version>${selenium.java.version}</version> 
    </dependency> 
</dependencies> 
<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.1</version> 
      <configuration> 
       <source>1.8</source> 
       <target>1.8</target> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

輸出 -打印測試處理2147483649

任何人都可以解釋我做錯了什麼。由於

+0

聲明一個字符串變量並在其中分配窗口句柄。 – iamsankalp89

+0

它有什麼不同?反正我試過了,結果是一樣的。 –

+0

你沒有得到所需的輸出 – iamsankalp89

回答

0

使用此code.Hopefully它會工作

String Parentswindows = driver.getWindowHandle(); 

    System.out.println("Parentswindows : " + Parentswindows); 
0

你嘗試這個 -

String window1 = driver.getWindowHandle(); 
System.out.println("Second window handle is "+window1); 
0

試試這個

public class SeleniumExample { 
public static void main(String args[]){ 
System.setProperty("webdriver.gecko.driver","/Users/raghavendr.kolisetty/Downloads/geckodriver"); 
WebDriver driver = new FirefoxDriver(); 
driver.manage().window().maximize(); 
driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS); 
driver.get("http://www.google.com"); 
System.out.println("printing test handles "+driver.getWindowHandle()); 
} 
} 

這種替換代碼:

public class SeleniumExample { 
public static void main(String args[]){ 
System.setProperty("webdriver.gecko.driver","/Users/raghavendr.kolisetty/Downloads/geckodriver"); 
WebDriver driver = new FirefoxDriver(); 
driver.manage().window().maximize(); 
driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS); 
driver.get("http://www.google.com"); 
String window1=driver.getWindowHandle(); 
System.out.println("printing test handles "+window1); 
} 
} 
相關問題