1. 程式人生 > >Selenium java環境登陸報錯Unable to find element on closed window

Selenium java環境登陸報錯Unable to find element on closed window

在利用selenium進行網站登陸的自動化測試時候,報錯org.openqa.selenium.NoSuchWindowException:Unable to find element on closed window(WARNING:the server did not provide any stacktrace infomation)

在網上查詢了大量的資訊,試了添加註冊表,修改iE的安全配置,管理員執行等

最後發現視窗時關閉之後再開啟的,視窗的控制代碼變化了,webdriver找不到原來的視窗了 //Store the current window handle String winHandleBefore = driver.getWindowHandle();

//Perform the click operation that opens new window

..........

//Switch to new window opened for(String winHandle : driver.getWindowHandles()){     driver.switchTo().window(winHandle); }

// Perform the actions on new window

參考:https://stackoverflow.com/questions/31134408/unable-to-find-element-on-closed-window-on-ie-11-with-selenium