基本我正在使用Maven與POM,並且我無法在第二個窗口中執行操作並單擊發送窗口關閉後自動關閉父窗口,之後,我的Firefox驅動程序不起作用。自動關閉窗口並切換回硒窗口中的父窗口
**我用低於提到的三個選項不工作**
public void switchWindow() {
String handle = driver.getWindowHandle();
Set<String> set = driver.getWindowHandles();
set.remove(handle);
if (set.size() >= 1) {
driver.switchTo().window((String) set.toArray()[0]);
}
public WebDriver switchWindowByTitle(String title)
{
WebDriver popup = null;
Set<String> windowIterator = driver.getWindowHandles();
System.err.println("No of windows : " + windowIterator.size());
for (String s : windowIterator) {
String windowHandle = s;
popup = driver.switchTo().window(windowHandle);
System.out.println("Window Title : " + popup.getTitle());
System.out.println("Window Url : " + popup.getCurrentUrl());
if (popup.getTitle().equals(title)){
System.out.println("Selected Window Title : " + popup.getTitle());
return popup;
}
}
System.out.println("Window Title :" + popup.getTitle());
System.out.println();
return popup;
public WebDriver switchWindowByTitle(String title)
{
String currentWindow = driver.getWindowHandle();
List<String> availableWindows = new ArrayList<String>(driver.getWindowHandles());
for(String w : availableWindows)
{
if (w != currentWindow)
{
driver.switchTo().window(w);
if (driver.getTitle().equalsIgnoreCase(title))
return true;
else
{
driver.switchTo().window(currentWindow);
}
}
}
return false;
}
能否請您參考http://stackoverflow.com/questions/19112209/how-to-handle-the-new-window-in-selenium-webdriver看到解決您的查詢? –
@AbdulHameed: - 我已經提到上面的鏈接,如果你可以看看我的第二個選項是同一個 –