org.openqa.selenium.NoSuchWindowException: 无法获取浏览器
org.openqa.selenium.NoSuchWindowException: Unable to get browser
我正在登录我的应用程序(IE 浏览器)。在主页上,它有消费者 link。我正在单击它。它会打开另一个 window.. 输入消费者 ID(仅必填字段)并保存。它正在被拯救。
现在如果我想查看已保存的消费者。我需要关闭 window 并需要将控制权转移到主页。我在关闭 window 后尝试 driver.switchTo.defaultContent()
。但它并没有改变控制。返回以下错误..
异常:
Exception in thread "main" org.openqa.selenium.NoSuchWindowException: Unable to get browser (WARNING: The server did not provide any stacktrace information)
代码:
import java.io.File;
import java.io.IOException;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
public class FirstTest {
public static void main(String[] args) throws IOException, InterruptedException {
// TODO Auto-generated method stub
File file = new File("IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
WebDriver driver = new InternetExplorerDriver();
driver.get("http://xx.xxx.xxx.xx/mysuite/Login.aspx");
driver.findElement(By.id("txtUser")).sendKeys("administrator");
driver.findElement(By.id("txtPwd")).sendKeys("password");
driver.findElement(By.id("cmdLogin")).click();
//Click Add customer (customer child window opens)
driver.findElement(By.linkText("Add Customer")).click();
driver.switchTo().window("Customer");
//Enter Customer ID and Save
driver.findElement(By.id("txtCode")).sendKeys("1234");
driver.findElement(By.id("cmdPageSave")).click();
//Close the child window
driver.findElement(By.id("cmdPageClose")).click();
//swith back to parent window
driver.switchTo().defaultContent();
Thread.sleep(3000);
driver.findElement(By.linkText("All customers")).click();
}
}
尝试在切换前存储处理程序名称。
public static void main(String[] args) throws IOException, InterruptedException {
// TODO Auto-generated method stub
File file = new File("IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
WebDriver driver = new InternetExplorerDriver();
driver.get("http://xx.xxx.xxx.xx/mysuite/Login.aspx");
driver.findElement(By.id("txtUser")).sendKeys("administrator");
driver.findElement(By.id("txtPwd")).sendKeys("password");
driver.findElement(By.id("cmdLogin")).click();
//Click Add customer (customer child window opens)
driver.findElement(By.linkText("Add Customer")).click();
//Store before switch
String mainHandle= driver.getWindowHandle();
driver.switchTo().window("Customer");
//Enter Customer ID and Save
driver.findElement(By.id("txtCode")).sendKeys("1234");
driver.findElement(By.id("cmdPageSave")).click();
//Close the child window
driver.findElement(By.id("cmdPageClose")).click();
//swith back to parent window
driver.switchTo().window(mainHandle);
Thread.sleep(3000);
driver.findElement(By.linkText("All customers")).click();
}
我正在登录我的应用程序(IE 浏览器)。在主页上,它有消费者 link。我正在单击它。它会打开另一个 window.. 输入消费者 ID(仅必填字段)并保存。它正在被拯救。
现在如果我想查看已保存的消费者。我需要关闭 window 并需要将控制权转移到主页。我在关闭 window 后尝试 driver.switchTo.defaultContent()
。但它并没有改变控制。返回以下错误..
异常:
Exception in thread "main" org.openqa.selenium.NoSuchWindowException: Unable to get browser (WARNING: The server did not provide any stacktrace information)
代码:
import java.io.File;
import java.io.IOException;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
public class FirstTest {
public static void main(String[] args) throws IOException, InterruptedException {
// TODO Auto-generated method stub
File file = new File("IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
WebDriver driver = new InternetExplorerDriver();
driver.get("http://xx.xxx.xxx.xx/mysuite/Login.aspx");
driver.findElement(By.id("txtUser")).sendKeys("administrator");
driver.findElement(By.id("txtPwd")).sendKeys("password");
driver.findElement(By.id("cmdLogin")).click();
//Click Add customer (customer child window opens)
driver.findElement(By.linkText("Add Customer")).click();
driver.switchTo().window("Customer");
//Enter Customer ID and Save
driver.findElement(By.id("txtCode")).sendKeys("1234");
driver.findElement(By.id("cmdPageSave")).click();
//Close the child window
driver.findElement(By.id("cmdPageClose")).click();
//swith back to parent window
driver.switchTo().defaultContent();
Thread.sleep(3000);
driver.findElement(By.linkText("All customers")).click();
}
}
尝试在切换前存储处理程序名称。
public static void main(String[] args) throws IOException, InterruptedException {
// TODO Auto-generated method stub
File file = new File("IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
WebDriver driver = new InternetExplorerDriver();
driver.get("http://xx.xxx.xxx.xx/mysuite/Login.aspx");
driver.findElement(By.id("txtUser")).sendKeys("administrator");
driver.findElement(By.id("txtPwd")).sendKeys("password");
driver.findElement(By.id("cmdLogin")).click();
//Click Add customer (customer child window opens)
driver.findElement(By.linkText("Add Customer")).click();
//Store before switch
String mainHandle= driver.getWindowHandle();
driver.switchTo().window("Customer");
//Enter Customer ID and Save
driver.findElement(By.id("txtCode")).sendKeys("1234");
driver.findElement(By.id("cmdPageSave")).click();
//Close the child window
driver.findElement(By.id("cmdPageClose")).click();
//swith back to parent window
driver.switchTo().window(mainHandle);
Thread.sleep(3000);
driver.findElement(By.linkText("All customers")).click();
}