0
如何處理它會自動關閉,並說,一個窗口一個窗口中找到錯誤如何處理它會自動關閉,並說,一個窗口一個窗口中找到錯誤
請找到下面的代碼:
driver.findElement(By.xpath("//span[contains(text(),'New Incident')]")).click();
Sleepforsec(10000);
Set<String> allWindowHandles = driver.getWindowHandles();
Iterator<String> it=allWindowHandles.iterator();
String parent=it.next();
String child=it.next();
System.out.println(parent +" ... "+child);
driver.switchTo().window(child);
Sleepforsec(8000);
driver.manage().timeouts().implicitlyWait(0,TimeUnit.SECONDS);
driver.findElement(By.xpath("//textarea[@id='arid_WIN_0_303530000']")).sendKeys("Bolton");
driver.manage().timeouts().implicitlyWait(60,TimeUnit.SECONDS);
driver.findElement(By.xpath("id('reg_img_304248190')")).click(); //for clicking search button
Sleepforsec(10000);
Set<String> allWindowHandles1 = driver.getWindowHandles();
Iterator<String> it1=allWindowHandles1.iterator();
String parent1=it1.next();
String child1=it1.next();
String child2=it1.next();//search
System.out.println(parent1 +" ... "+child2);
driver.switchTo().window(child2);
Sleepforsec(6000);
Actions builder = new Actions(driver);
WebElement e1 = driver.findElement(By.xpath("//span[text()='Brent']"));
//use DoubleClick method to double click on any element
builder.doubleClick(e1).build().perform();
driver.findElement(By.className("btntextdiv")).click();// this is where window closes automatically. Then It shud switch back to previous window.
driver.switchTo().window(Child);
我不知道Sleepforsec是什麼,但應該使用Sleeper.sleepTight。 – djangofan