Reputation: 50
I'm getting an error for starting multiple driver.get commands in an loop. I have looked at people with similar problems i.e org.openqa.selenium.NoSuchSessionException: no such session error in Selenium automation tests using ChromeDriver Chrome with Java but the problem there was the jdk version, chrome version and such. I can start one get command for each instance of webdriver so i don't belive it's a version of my jdk,chromedriver or selenium that's the problem.
String[] referenceID = reference;
String[] commandID = command;
String url = "https://"+website;
System.out.println(Arrays.deepToString(referenceID));
System.out.println(Arrays.deepToString(commandID));
System.out.println("Done");
System.setProperty("webdriver.chrome.driver","D:\\selenium\\libs\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
long waitTime = 0;
long start = System.nanoTime();
int times = gui.getTestAmount();
int i = 0;
boolean reset = false;
driver.get(url);
while(times != 0) {
if(reset) {
try {
Thread.sleep(9000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
driver.get(url);
reset = false;
}
if(commandID[i].equals("Click")) {
driver.findElement(By.xpath(referenceID[i])).click();
System.out.println("Clicked");
}
if (commandID[i].equals("Text")) {
System.out.println("testing text");
String s = referenceID[i];
String id = s.substring(0, s.indexOf(' '));
System.out.println(id);
String content = s.substring(s.indexOf(' ') + 1);
System.out.println(content);
driver.findElement(By.xpath(id)).sendKeys(content);
}
if (commandID[i].equals("Wait")) {
try {
Thread.sleep(Integer.parseInt(referenceID[i])*1000);
waitTime += (Integer.parseInt(referenceID[i])*1000);
System.out.println("Waited");
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Waited done");
}
i++;
if(i>referenceID.length-1) {
System.out.println("in reset");
reset = true;
driver.close();
i=0;
times--;
}
}
The error:
Exception in thread "AWT-EventQueue-0" org.openqa.selenium.NoSuchSessionException: invalid session id
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'LAPTOP-E1N87PDH', ip: 'XXXXXXXX(edited out myself)', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '13.0.1'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 83.0.4103.116, chrome: {chromedriverVersion: 83.0.4103.39 (ccbf011cb2d2b..., userDataDir: C:\Users\marti\AppData\Loca...}, goog:chromeOptions: {debuggerAddress: localhost:56414}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:virtualAuthenticators: true}
Session ID: ea7286c558f6d6969eb16fcb410e68af
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:277)
at data.getInfo.print(getInfo.java:39)
at gui.gui.lambda$5(gui.java:153)
at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
at java.desktop/java.awt.Component.processMouseEvent(Component.java:6636)
at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
at java.desktop/java.awt.Component.processEvent(Component.java:6401)
at java.desktop/java.awt.Container.processEvent(Container.java:2263)
at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5012)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4844)
at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918)
at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4547)
at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2762)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4844)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Upvotes: 2
Views: 3521
Reputation: 11421
/**
* Close the current window, quitting the browser if it's the last window currently open.
*/
void close();
You don't need to close between gets -- each get will reload the contents of the browser window.
Upvotes: 1
Reputation: 83
I am guessing the issue was initiating driver inside if statement. Can you try giving driver.get(url);
before while(times != 0)
Believe driver is getting inactive after if block was completed so that other elements are not responding. Refer this for more solutions
Upvotes: 0