1

I was trying to execute a program which is on Desktop from the command line :

javac 'BrowserStackTest.java'

Body of the program:

import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Test;
  
import java.net.URL;

public class BrowserStackTest {

}

And I got the below error:

BrowserStackTest.java:1: error: package org.openqa.selenium does not exist
    import org.openqa.selenium.By;
                              ^
BrowserStackTest.java:2: error: package org.openqa.selenium does not exist
    import org.openqa.selenium.Platform;
                              ^
BrowserStackTest.java:3: error: package org.openqa.selenium does not exist
    import org.openqa.selenium.WebDriver;
                              ^
BrowserStackTest.java:4: error: package org.openqa.selenium does not exist
    import org.openqa.selenium.WebElement;
                              ^
BrowserStackTest.java:5: error: package org.openqa.selenium.remote does not exist
    import org.openqa.selenium.remote.DesiredCapabilities;

From the error I was able to observe that I am not providing the jars for the execution, but I am unable to provide them due to lack of enough documentation such as where to add the jars for execution of such programs.

Jan Schultke
  • 17,446
  • 6
  • 47
  • 96
Martell
  • 23
  • 1
  • 5
  • 1
    Please don't mind that class is empty – Martell Feb 21 '19 at 12:22
  • 1
    use -cp option to specify the jars to include like here https://stackoverflow.com/questions/25025018/javac-classpath-option-with-multiple-jar-files-in-current-directory-causing-erro – Nadir Feb 21 '19 at 12:27
  • @Nadir Thanks it worked javac -cp "selenium-2.48.2/selenium-java-2.48.2.jar;selenium-2.48.2/selenium-java-2.48.2-srcs.jar;selenium-2.48.2/libs/*" BrowserStackTest.java But i got some more info after executing with the above Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. – Martell Feb 21 '19 at 12:47
  • In Continuation to the above comment upon executing the class java BrowserStackTest Got the below Error Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/Capabilities at java.lang.Class.getDeclaredMethods0(Native Method) Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.Capabilities – Martell Feb 22 '19 at 06:56

1 Answers1

1

I solved this problem by: 1- download selenium jar file from here , name should be like "client-combined-3.141.59.jar"

2-include the jar file in libs folder.

3-in app build.gradle add below line:

implementation files('libs/client-combined-3.141.59.jar')