我正在使用Selenium来自动化一些测试。 WebDriver api getWindowHandle()
始终返回2147483649
。它实际上应该返回像{9e10f4f4-2da6-ef43-b463-1b0d576e7dae}
这样的字母数字字符串,它通常随着每次测试运行而变化。但我总是2147483649
。我正在使用Selenium 3.5.1和Firefox 55.0.2。
重现问题的代码 -
爪哇
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 :(得分:0)
使用此代码。希望它能正常工作
String Parentswindows = driver.getWindowHandle();
System.out.println("Parentswindows : " + Parentswindows);
答案 1 :(得分:0)
你试过这个 -
String window1 = driver.getWindowHandle();
System.out.println("Second window handle is "+window1);
答案 2 :(得分: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);
}
}