Closing a popup-window with geb after an alert - selenium

I'm trying to achieve the following using the Geb Testing Framework:
I've opened a popup-window
I click on a button
An alert is raised
After clicking ok the popup is closed. (which is my actual problem)
I'm using this code which raises a 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()
}
}
I'm getting this error:
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)
The problem is that I want to close the window. There is some data shared between the popup and the parent window and after selecting the right value in the popup this window should close.
I already tried to catch the exception. But then I would need to tell Geb to use the right window (the parent window which is still open).
Any ideas?

By default Geb closes the window opened via a withNewWindow() call at the end of the execution of that method. You can ask it not to do so using the close option:
withNewWindow({ selectLink.click() }, close: false) {
...
}

So if i read that right, your clicking OK on the alert, then you get the error.
Sounds like Geb doesn't know what page it's on and you need to wrap your code with a waitFor:
waitFor {
withWindow({ isAt MyPage}) { true }
}

Related

org.openqa.selenium.WebDriverException: unknown error: cannot get automation extension

Chrome Driver is not able to maximize the window :
ChromeDriver Version:2.24.417431
Chrome Version :57.0.2987.110
org.openqa.selenium.WebDriverException: unknown error: cannot get automation extension
from unknown error: page could not be found: chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/_generated_background_page.html
(Session info: chrome=57.0.2987.110)
(Driver info: chromedriver=2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf),platform=Windows NT 6.3.9600 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 10.02 seconds
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
System info: host: 'JMP-CPE-MSDC01', ip: '169.254.133.0', os.name: 'Windows Server 2012 R2', os.arch: 'x86', os.version: '6.3', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf), userDataDir=D:\TempFiles\scoped_dir31332_1125}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=57.0.2987.110, platform=WIN8_1, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 048637a3378f2564ab12cb3eb3d2837b
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
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.getScreenshotAs(RemoteWebDriver.java:335)
at com.automate.SeleniumWrapper.GenUtils.getSnapShot(GenUtils.java:33)
at com.automate.SeleniumWrapper.stepExecutor.StepDriver(stepExecutor.java:4795)
at com.automate.testSuite.Shadow.ShadowScenario.ReEncryption443734(ShadowScenario.java:607)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:100)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:646)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:811)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1137)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:753)
at org.testng.TestRunner.run(TestRunner.java:607)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:368)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:363)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:321)
at org.testng.SuiteRunner.run(SuiteRunner.java:270)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1284)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1209)
at org.testng.TestNG.runSuites(TestNG.java:1124)
at org.testng.TestNG.run(TestNG.java:1096)
at com.automate.Run.DTVProjectRun.main(DTVProjectRun.java:41)
}
You need to upgrade your version of Chromedriver as the version you are using does not support the version of Chrome you are using.
The latest version can be downloaded here:
https://sites.google.com/a/chromium.org/chromedriver/downloads

Exception with HtmlUnit 2.23 + Selenium 2.53.1

I have an error when I try to execute HtmlUnit 2.23 + Selenium 2.53.1.
The full log is:
org.openqa.selenium.WebDriverException: com.gargoylesoftware.htmlunit.ScriptException: Exception invoking getUrl
Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09'
System info: host: 'XXX', ip: '0.0.0.0', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_60'
Driver info: driver.version: HtmlUnitDriver
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:554)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:530)
at utils.MyDriverExecutor.getDriver(MyDriverExecutor.java:86)
at utils.MyExecution.accessURL(MyExecution.java:22)
at utils.MyExecution.acessaSistema(MyExecution.java:60)
at com.mycompany.mysoftware.steps.LoginSteps.queEstouNaTelaDeLoginDoSistema(LoginSteps.java:22)
at ✽.Dado que estou na tela de login do sistema(/trunk/test/testCases/1-LoginCadastroNovoCliente.feature:10)
Caused by: com.gargoylesoftware.htmlunit.ScriptException: Exception invoking getUrl
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:921)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:628)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:515)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:803)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:779)
at com.gargoylesoftware.htmlunit.html.HtmlPage.loadExternalJavaScriptFile(HtmlPage.java:975)
at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:352)
at com.gargoylesoftware.htmlunit.html.HtmlScript$2.execute(HtmlScript.java:238)
at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:257)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:772)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:729)
at net.sourceforge.htmlunit.cyberneko.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1209)
at net.sourceforge.htmlunit.cyberneko.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1111)
at net.sourceforge.htmlunit.cyberneko.filters.DefaultFilter.endElement(DefaultFilter.java:207)
at net.sourceforge.htmlunit.cyberneko.filters.NamespaceBinder.endElement(NamespaceBinder.java:337)
at net.sourceforge.htmlunit.cyberneko.HTMLScanner$ContentScanner.scanEndElement(HTMLScanner.java:3137)
at net.sourceforge.htmlunit.cyberneko.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2100)
at net.sourceforge.htmlunit.cyberneko.HTMLScanner.scanDocument(HTMLScanner.java:927)
at net.sourceforge.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:506)
at net.sourceforge.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:459)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.parse(HTMLParser.java:979)
at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:241)
at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:187)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:269)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:157)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:512)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:386)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:304)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:451)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:541)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:530)
at utils.MyDriverExecutor.getDriver(MyDriverExecutor.java:86)
at utils.MyExecution.accessURL(MyExecution.java:22)
at utils.MyExecution.acessaSistema(MyExecution.java:60)
at com.mycompany.mysoftware.steps.LoginSteps.queEstouNaTelaDeLoginDoSistema(LoginSteps.java:22)
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:497)
at cucumber.runtime.Utils$1.call(Utils.java:37)
at cucumber.runtime.Timeout.timeout(Timeout.java:13)
at cucumber.runtime.Utils.invoke(Utils.java:31)
at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:38)
at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)
at cucumber.runtime.Runtime.runStep(Runtime.java:299)
at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44)
at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:165)
at cucumber.runtime.Runtime.run(Runtime.java:121)
at cucumber.api.cli.Main.run(Main.java:36)
at cucumber.api.cli.Main.main(Main.java:18)
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:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.NullPointerException
at com.gargoylesoftware.htmlunit.javascript.host.WebSocket.getUrl(WebSocket.java:256)
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:497)
at net.sourceforge.ht
mlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:153)
... 74 more
The HtmlUnit didn't call none of the test cases ( Cucumber )

alert not getting detected in selenium 3.0.0-beta2

i am using selenium 3.0.0-beta2 , my alert is not getting detected with below code.
Alert alert = driver.switchTo().alert();
String Actual = alert.getText();
below is the stack trace
org.openqa.selenium.UnhandledAlertException: unexpected alert open: {Alert text : Company Already Exists}
(Session info: chrome=52.0.2743.116)
(Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Windows NT 6.1 SP1 x86) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 52 milliseconds: null
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:55:52'
System info: host: 'tct4-PC', ip: '192.168.0.60', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_45'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={chromedriverVersion=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4), userDataDir=C:\Users\tct4\AppData\Local\Temp\scoped_dir460432_24766}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=52.0.2743.116, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 6f2f063385fd93923cab757a17e7364a
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:422)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:164)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:670)
at org.openqa.selenium.remote.RemoteWebDriver.getScreenshotAs(RemoteWebDriver.java:325)
at com.tfleet.utilities.TakeScreenshot.takeScreenshot(TakeScreenshot.java:19)
at regression.Master.AddCompanyTest.addCompanyTest(AddCompanyTest.java:144)
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:497)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:74)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:121)
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:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Info is not complete which browser you are using. If you are using with ChromeDriver then update your chrome browser and Download latest version of chromedriver from this link http://chromedriver.storage.googleapis.com/index.html. and use wait command then use it will work.
If u are using firefox then let me know.
Use this to handle the alert:
driver.switchTo().alert().accept();

Timeout exception is showing after button click

After button click page get refresh and redirect to another page.In my case after button click i gave timeout for page refresh but after button click it showing timeout exception without time wait .i used all type of time wait event i used thread.sleep() but no use.
Exception :
FAILED: createEventTest
org.openqa.selenium.TimeoutException: Timed out waiting for page load.
Command duration or timeout: 15.08 seconds
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
System info: host: 'pc', ip: '192.168.1.6', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.7.0_79'
Session ID: a29803a6-5ec1-4791-b26f-3ab0adb47c7b
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=WINDOWS, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, nativeEvents=false, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=46.0.1}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
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.RemoteWebElement.execute(RemoteWebElement.java:327)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:51)
at com.sun.proxy.$Proxy6.click(Unknown Source)
at com.pv.pages.CreateEventPage.createApprovedEvent(CreateEventPage.java:356)
at com.pv.pages.CreateEventPage.createEvent(CreateEventPage.java:688)
at com.pv.tests.CreateEventTests.createEventTest(CreateEventTests.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:643)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:782)
at org.testng.TestRunner.run(TestRunner.java:632)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1246)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1171)
at org.testng.TestNG.run(TestNG.java:1066)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:113)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:206)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:177)
Caused by: org.openqa.selenium.TimeoutException: Timed out waiting for page load.
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
System info: host: 'pc', ip: '192.168.1.6', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.7.0_79'
Driver info: driver.version: unknown
at .Utils.installClickListener/e<(file:///C:/Users/fu/AppData/Local/Temp/anonymous7103862578695056607webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:9372)
at .WebLoadingListener/e(file:///C:/Users/fu/AppData/Local/Temp/anonymous7103862578695056607webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:5142)
at .WebLoadingListener/<(file:///C:/Users/fu/AppData/Local/Temp/anonymous7103862578695056607webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:5150)
at .fxdriver.Timer.prototype.setTimeout/<.notify(file:///C:/Users/fu/AppData/Local/Temp/anonymous7103862578695056607webdriver-profile/extensions/fxdriver#googlecode.com/components/command-processor.js:625)
Tried this?
driver.manage().timeouts().pageLoadTimeout(10,TimeUnit.SECONDS);
I used to javascript for page load .Now my code running fine.
public static void waitForPageToLoad() {
do {
js = (JavascriptExecutor) driver;
pageLoadStatus = (String)js.executeScript("return document.readyState");
System.out.print(".");
} while ( !pageLoadStatus.equals("complete") );
System.out.println();
System.out.println("Page Loaded.");
}

selenium webdriver in Internet Explorer throwing an error even after done all required setting

public class FirstTest { WebDriver driver; #Test public void test() { System.setProperty("webdriver.ie.driver","C:\\Users\\Priyanka\\Documents\\datadriver\\IEDriverServer.exe"); driver=new InternetExplorerDriver(); //driver=new FirefoxDriver(); driver.manage().window().maximize(); driver.get("http://gmail.com"); driver.findElement(By.id("userid")).sendKeys("Abc#gmail.coms"); driver.findElement(By.id("pwd")).sendKeys("abc#167"); driver.findElement(By.name("Submit")).click(); } }
This is my code.It will open the given URL but thows an error when trying to find webelement Error message:
FAILED: test org.openqa.selenium.NoSuchWindowException: Unable to find
element on closed window (WARNING: The server did not provide any
stacktrace information) Command duration or timeout: 28 milliseconds
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09
19:55:52' System info: host: 'Priyanka-PC', ip: '100.74.201.94',
os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1',
java.version: '1.7.0_79' *** Element info: {Using=id, value=userid}
Session ID: fc075a9b-5a50-42fa-ba96-ce2258254d4a Driver info:
org.openqa.selenium.ie.InternetExplorerDriver Capabilities
[{platform=WINDOWS, javascriptEnabled=true, elementScrollBehavior=0,
ignoreZoomSetting=false, enablePersistentHover=true,
ie.ensureCleanSession=false, browserName=internet explorer,
enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss,
version=-1, pageLoadStrategy=normal, ie.usePerProcessProxy=false,
cssSelectorsEnabled=true, ignoreProtectedModeSettings=false,
requireWindowFocus=false, initialBrowserUrl=http://localhost:22334/,
handlesAlerts=true, ie.forceCreateProcessApi=false, nativeEvents=true,
browserAttachTimeout=0, ie.browserCommandLineSwitches=,
takesScreenshot=true}] at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
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:647)
at
org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:353)
at
org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:403)
at org.openqa.selenium.By$ById.findElement(By.java:218) at
org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:345)
at demo.FirstTest.test(FirstTest.java:20) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606) at
org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:643) at
org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820) at
org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128) at
org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at
org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:782) at
org.testng.TestRunner.run(TestRunner.java:632) at
org.testng.SuiteRunner.runTest(SuiteRunner.java:366) at
org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361) at
org.testng.SuiteRunner.privateRun(SuiteRunner.java:319) at
org.testng.SuiteRunner.run(SuiteRunner.java:268) at
org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at
org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at
org.testng.TestNG.runSuitesSequentially(TestNG.java:1246) at
org.testng.TestNG.runSuitesLocally(TestNG.java:1171) at
org.testng.TestNG.run(TestNG.java:1066) at
org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:113) at
org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:206) at
org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:177)
I have done below settings:
Set Security zone
Made entry in Registry file
Set environment variable
Set default zoom size to 100 Please guide what should i do.
This code is working fine in firefox
Try this.
Enable protected mode for all zones in IE browser. It should be checked for all zones.
It worked for me.