1

I am developing in VSCode with the Java Extension Pack (which includes Maven).

For some reason, my program (below) does not terminate after running.

import java.util.Scanner;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

Scanner in = new Scanner(System.in);
System.setProperty("webdriver.chrome.driver", "Path to exe\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.quit();

System.out.println("Press enter to quit");
in.nextLine();
in.close();

The Selenium chrome tab opens for a moment and then closes (as I would expect). The program then prompts me to "press enter", which I do, but the program does not end after that. It only ends if I press Ctrl-c (at which point it asks if I want to terminate the batch job).

If I comment out the Selenium stuff, it works fine - the program ends after I press enter. Below is a picture of the log:

enter image description here

Do you think the part about the log error could be the cause? That part is not there when I comment out the Selenium stuff. Also, I hope you don't mind I censored some personal information.

Please let me know if there is anything I can do to make this question easier to answer.

Update: I fixed the log issue by including the slf4j-jdk14 dependency but that didn't have any impact - the program still didn't shut down. The only difference now is that the log no longer contains the lines beginning with "SLF4J"

invzbl3
  • 5,872
  • 9
  • 36
  • 76
manissss
  • 101
  • 1
  • 12

3 Answers3

2

I have the exact same problem, and I am still researching the problem. However, I have fixed the issue by downgrading the Selenium-Java Maven-dependency from version 4.0.0-alpha-6 to version 3.141.59. My application is exiting as expected after the downgrade.

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.141.59</version>
    </dependency>

I will update my answer as I find out more.

dma
  • 89
  • 7
0

This feels like more of a work-around than an answer, but if you add System.exit(0); at the end of the program then it exits (as you would expect). I don't know what about the Selenium code makes it necessary to do explicitly exit though.

manissss
  • 101
  • 1
  • 12
  • 1
    This shouldn't be necessary. What version of Selenium are you using? By downgrading to the latest stable version, as I suggested below, I got my app exiting normally without adding explicit system exit. – dma Jul 11 '20 at 18:50
  • I am using 4.0.0-alpha-6. I will try downgrading – manissss Jul 13 '20 at 21:06
  • Did the downgrading help you? Would be very happy if you could select my reply below as the accepted answer. @manissss – dma May 16 '21 at 19:40
  • Well, downgrading fixed the issue but wasn't really an option for me since it broke other things. The issue ended up being resolved when they released newer versions. I can definitely accept your answer, I just don't know what the stack overflow protocol mandates in this situation: while your answer technically did solve the problem, it just wasn't the solution for my scenario. Let me know what you think. – manissss May 18 '21 at 21:00
0

Thanks @dma downgrading to 3.141.59 - did the trick and now my program is terminating

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-chrome-driver</artifactId>
    <version>3.141.59</version>
</dependency>
Sandeep Sharma
  • 109
  • 2
  • 15