Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am using Selenium WebDriver, Jsoup, Opencsv, and Java to parse HTML pages including javascript of one website, and then generate csv file. I can run it from Eclipse but I want to automate it using batch file. My java program has two classes - main and website. So I copied those two classes that generated by Eclipse and put it in one folder. Then I also copied all the external jar files such as selenium 2.33.0, opencsv-2.3 and jsoup 1.7.2, and created batch file in the same folder as

@ECHO OFF
Java Main pause

Then I tried to run batch file, but it failed. I tried again to change the batch file as

@ECHO OFF
set CLASSPATH=.
set CLASSPATH=%CLASSPATH%;C:\Data\Website\selenium-2.33.0\selenium-2.33.0\selenium-2.33.0\*.jar;C:\Data\Website\selenium-2.33.0\selenium-2.33.0\selenium-2.33.0\libs\*.jar
Java Main
pause

but still the same error produced as

Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/W
ebDriver
        at Main.main(Main.java:6)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.WebDriver
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
        ... 1 more
Press any key to continue . . .

Kindly help. I searched how to run Selenium webdriver tests from batch file but I found out that JUnit is needed. I just use Java, and third party libraries to get my requirements. Thanks advance.

share|improve this question

1 Answer 1

This answer is easy.

@ECHO off
SET "SELDIR=C:\Data\Website\selenium-2.33.0"
SET "CLASSPATH=.;%SELDIR%\*.jar;%SELDIR%\libs\*.jar"
"%JAVA_HOME%\bin\java.exe" -cp "%CLASSPATH%" MainClassName arg1 arg2
PAUSE
share|improve this answer
    
I tried your code but still got the same error from cmd. I can't also see org/openqa/selenium/WebDriver folders in that selenium-2.33.0 folder that was downloaded and extracted. But when I used Selenium Webdriver in Eclipse, I used as the following without those folders and sub folders and got no error in Eclipse. –  Mira Jul 2 '13 at 6:44
    
import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; –  Mira Jul 2 '13 at 6:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.