【发布时间】:2017-05-05 16:20:57
【问题描述】:
在处理我的 java selenium 项目时,我遇到了这个非常奇怪的问题。当我在工作时,我编写并运行我编写的代码没有问题,但是当我回到家时,编写代码并尝试在 Eclipse 中编译它给了我:
Exception in thread "main" org.openqa.selenium.NoSuchWindowException: Unable to find element on closed window (WARNING: The server did not provide any stacktrace information)
当我将代码从家里带入我的工作计算机时,它会编译并运行。所以我知道这不是问题。
问题:如何让这个程序在家中在我的电脑上运行?这就是我正在使用的驱动程序(IE)。它崩溃的部分是每当我以任何方法甚至在 main 中调用 xPath 时。希望得到一些帮助,谢谢。
public static WebDriver driver(){
System.setProperty("webdriver.ie.driver", "D:/Selenium/IEDriverServer.exe");
DesiredCapabilities dc = DesiredCapabilities.internetExplorer();
dc.setCapability("EnableNativeEvents", false); //Disable native events
dc.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); // Issue with downloading the report
dc.setCapability("ignoreZoomSetting",true);
WebDriver thing = new InternetExplorerDriver(dc);
thing.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
thing.findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL, "0")); //Set zoom level to 100%
return thing;
}
【问题讨论】:
-
您声明每当您使用 XPath 时都会发生错误,但我在上面的代码中没有看到任何使用 XPath 的内容。通常,“NoSuchWindow”类型的错误意味着预期的浏览器选项卡未打开或浏览器本身未打开。它是否完全打开浏览器?在我看来,IE webbrowser 驱动程序比 chrome 或 firefox 驱动程序更复杂和错误。
-
谢谢比尔。 IE 窗口会自动打开一个 get(URL)。使用 get 后,我使用我的 xPath("...") 来查找要单击的页面链接。我环顾四周,看到人们使用了很多 Firefox 和 chrome。 IE上不多。可能只是切换到Firefox。
-
我会尝试在程序中放置一个调试点并逐步查找导致异常的行。随意展示您的第一个使用 XPath 的 findelement 命令的示例,您可能错过了某些内容(我们有时都会这样做)
-
@BillHileman 请允许我在
IE webbrowser driver is a lot more complicated and buggy than chrome or firefox drivers上不同意你的观点:) IMO,Web 应用程序的实现肯定会因浏览器而异。有时,IE 浏览器的行为与 chrome 或 firefox 浏览器相比有些不同,但并不复杂。毕竟Bug是组成开发人员/测试人员团队的词:) -
@BillHileman 感谢您告知有关 Chrome 驱动程序的信息。工作 100000 次更好更快。唯一的问题是程序结束时它不会关闭驱动程序。但这是吹毛求疵。
标签: java selenium xpath driver