0
我登錄到我的應用程序(IE瀏覽器)。在主頁上,它具有消費者鏈接。我點擊它..它會打開另一個窗口..輸入消費者ID(僅限必填字段)並保存。它正在得到保存。org.openqa.selenium.NoSuchWindowException:無法獲取瀏覽器
現在如果我想查看保存的消費者。我需要關閉窗口並需要將控件傳輸到主頁。關閉窗口後我正在嘗試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();
}
}
你是在同一個標籤還是兩個標籤中做這個? – LittlePanda
當你點擊消費者鏈接時,你的窗口是否會刷新。 –