gpt4 book ai didi

selenium - 警报后使用 geb 关闭弹出窗口

转载 作者:行者123 更新时间:2023-11-28 21:24:33 26 4
gpt4 key购买 nike

我正在尝试使用 Geb 测试框架实现以下目标:

  1. 我打开了一个弹出窗口
  2. 我点击一个按钮
  3. 发出警报
  4. 单击“确定”后,弹出窗口将关闭。 (这是我的实际问题)

我正在使用引发 WindowNotFoundException 的代码:

// open the popup by clicking the link (javascript)
withNewWindow({ selectLink.click() }) {
// doing some other stuff in the opened window

// closing the window by clicking a button
// Javascript will close the window after the alert is closed
withAlert { // <- The error is raised here
$(".select").click()
}
}

我收到这个错误:

org.openqa.selenium.NoSuchWindowException: Window not found. The browser window may have been closed.
Command duration or timeout: 15 milliseconds
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
System info: host: 'dev1b', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.16.0-4-amd64', java.version: '1.8.0_92'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=45.7.0, platform=LINUX, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 9b775683-e9c9-4651-a5fd-2c1f5e9fcb91

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:701)
at org.openqa.selenium.remote.RemoteWebDriver.getPageSource(RemoteWebDriver.java:511)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.metaclass.MethodMetaProperty$GetBeanMethodMetaProperty.getProperty(MethodMetaProperty.java:76)
at org.codehaus.groovy.runtime.callsite.GetEffectivePojoPropertySite.getProperty(GetEffectivePojoPropertySite.java:64)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:296)
at geb.report.PageSourceReporter.getPageSource(PageSourceReporter.groovy:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
at geb.report.PageSourceReporter.writePageSource(PageSourceReporter.groovy:38)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:174)
at geb.report.PageSourceReporter.writeReport(PageSourceReporter.groovy:29)
at geb.report.Reporter$writeReport.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at geb.report.CompositeReporter.writeReport(CompositeReporter.groovy:31)
at geb.report.Reporter$writeReport.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at geb.Browser.report(Browser.groovy:927)
at geb.Browser$report$8.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at geb.junit4.GebReportingTest.report(GebReportingTest.groovy:37)
at geb.junit4.GebReportingTest.writeGebReport(GebReportingTest.groovy:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:33)
at org.junit.rules.TestWatchman$1.evaluate(TestWatchman.java:53)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.openqa.selenium.NoSuchWindowException: Window not found. The browser window may have been closed.
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
System info: host: 'dev1b', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.16.0-4-amd64', java.version: '1.8.0_92'
Driver info: driver.version: unknown
at <anonymous class>.nsCommandProcessor.prototype.execute(file:///tmp/anonymous1889291378920456774webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12719)
at <anonymous class>.Dispatcher.executeAs/<(file:///tmp/anonymous1889291378920456774webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:9558)
at <anonymous class>.Resource.prototype.handle(file:///tmp/anonymous1889291378920456774webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:9705)
at <anonymous class>.Dispatcher.prototype.dispatch(file:///tmp/anonymous1889291378920456774webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:9652)
at <anonymous class>.WebDriverServer/<.handle(file:///tmp/anonymous1889291378920456774webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:12517)
at <anonymous class>.createHandlerFunc/<(file:///tmp/anonymous1889291378920456774webdriver-profile/extensions/fxdriver@googlecode.com/components/httpd.js:2054)
at <anonymous class>.ServerHandler.prototype.handleResponse(file:///tmp/anonymous1889291378920456774webdriver-profile/extensions/fxdriver@googlecode.com/components/httpd.js:2387)
at <anonymous class>.Connection.prototype.process(file:///tmp/anonymous1889291378920456774webdriver-profile/extensions/fxdriver@googlecode.com/components/httpd.js:1223)
at <anonymous class>.RequestReader.prototype._handleResponse(file:///tmp/anonymous1889291378920456774webdriver-profile/extensions/fxdriver@googlecode.com/components/httpd.js:1677)
at <anonymous class>.RequestReader.prototype._processBody(file:///tmp/anonymous1889291378920456774webdriver-profile/extensions/fxdriver@googlecode.com/components/httpd.js:1525)
at <anonymous class>.RequestReader.prototype.onInputStreamReady(file:///tmp/anonymous1889291378920456774webdriver-profile/extensions/fxdriver@googlecode.com/components/httpd.js:1393)

问题是我想关闭窗口。弹出窗口和父窗口之间共享一些数据,在弹出窗口中选择正确的值后,该窗口应该关闭。

我已经 try catch 异常。但是我需要告诉 Geb 使用正确的窗口(仍然打开的父窗口)。

有什么想法吗?

最佳答案

默认情况下,Geb 在该方法执行结束时关闭通过 withNewWindow() 调用打开的窗口。您可以使用 close option 要求它不要这样做:

withNewWindow({ selectLink.click() }, close: false) {
...
}

关于selenium - 警报后使用 geb 关闭弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43869086/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com