![](/img/trans.png)
[英]IE 11 with Selenium WebDriver: org.openqa.selenium.NoSuchWindowException
[英]Exception (org.openqa.selenium.NoSuchWindowException): using Selenium WebDriver with Java in Internet Explorer
使用IE進行自動化使用Selenium Webdriver時,我可以打開URL,但在該頁面上找到該元素會引發以下異常:
org.openqa.selenium.NoSuchWindowException:無法在關閉的窗口中找到元素(警告:服務器未提供任何堆棧跟蹤信息)
我嘗試過driver.switchTo.window()
方法,但它無法正常工作。 我已經搜索了幾個小時,我沒有到達任何地方。
這是代碼:
public static Selenium selenium;
public static void main(String args[]) {
try {
System.setProperty(
"webdriver.ie.driver",
"D:\\Driver\\IEDriverServer_Win32_2.32.3_latest\\IEDriverServer.exe");
DesiredCapabilities capab = DesiredCapabilities.internetExplorer();
capab.setCapability(
InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
true);
WebDriver driver = new InternetExplorerDriver(capab);
driver.get("http://www.google.com");
driver.findElement(By.xpath(".//*[@id='addlang']/a[1]")).click();
} catch (Exception e) {
e.printStackTrace();
}
}
刪除功能INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS
並手動將IE保護模式設置設置為對所有區域都相同。
資源:
case "ie_driver":
//IE CODE
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
cap.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, "https://testvmm6.partnersonline.com/vmm");
cap.internetExplorer().setCapability("ignoreProtectedModeSettings", true);
System.setProperty("webdriver.ie.driver", System.getProperty("user.dir")+"//exe//IEDriverServer1.exe");
cap.setCapability("IE.binary", "C:/Program Files (x86)/Internet Explorer/iexplore.exe");
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setJavascriptEnabled(true);
cap.setCapability("requireWindowFocus", true);
cap.setCapability("enablePersistentHover", false);
幫助我的問題是設置初始頁面(IE 11都是32和64)
private WebDriver getIEDriver() {
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, INIT_PAGE);
File file = new File("E:/drivers/IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
return new InternetExplorerDriver(cap);
}
這里最好的選擇是對注冊表進行一些調整:
轉到注冊表編輯(從Windows運行regedit
)
在HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\InternetSettings\\Zones
下的注冊表中查找。 在那里,你應該看到鍵號0-4。 在這些鍵0-4下,查找名為2500的值
對於0-4中的所有鍵,對於值2500具有相同的數據。例如,對於鍵0,如果值2500具有數據3(十六進制數據),則對於所有其他鍵,將值2500的數據設為3 (1,2,3,4)。
現在嘗試運行腳本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.