Selenium - Java : PhantomJS : Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.remote.HttpVerb - selenium

I am trying to instantiate a PhantomJS Driver with Selenium Java. Below is the code :
File file = new File("C:\\Softwares\\drivers\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe");
System.setProperty("phantomjs.binary.path", file.getAbsolutePath());
WebDriver driver = new PhantomJSDriver();
driver.get("http://www.google.com");
I have tried with different versions of Selenium and I am getting the same exception :
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.remote.HttpVerb
java.lang.NoClassDefFoundError: org/openqa/selenium/remote/HttpVerb
at org.openqa.selenium.phantomjs.PhantomJSDriver.getCustomCommands(PhantomJSDriver.java:166)
at org.openqa.selenium.phantomjs.PhantomJSCommandExecutor.<init>(PhantomJSCommandExecutor.java:62)
at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:110)
I'm using the below list of dependencies in my project :
phantomjsdriver
selenium-common.jar
selenium-java 2.53.1 . jar
The reason I'm using an outdated version of selenium library is due to some article I found over the internet saying that remote/HttpVerb is deprecated and downgrading the library would remove the error. However, I'm still getting this error

Please check this dependancy in POM
<dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-remote-driver</artifactId>
      <version>2.53.1</version>
    </dependency>
Check whether this class is present or not

Related

Have problem with my automation selenium code on launching simple chrome browser

I am just starting my automation testing but landed with some error tired with debugging can someone please help here i have java libraries & selenium server standalone.
Error/
Error occurred during initialization of boot layer
java.lang.module.FindException: Unable to derive module descriptor for
D:\browser\selenium-server-standalone-3.141.59.jar Caused by:
java.lang.module.InvalidModuleDescriptorException: Provider class
org.eclipse.jetty.http.Http1FieldPreEncoder not in module
You need to use following
Webdriver driver = new ChromeDriver();
instead of
Webdriver driver = new ChromeDriverInfo();
Hope this will resolve your problem.
You haven't created a package.
-Inside the Java project: Create a new package
-Inside that package: Create a new Java class
-Copy and Paste this code into that file.
use this code :
Webdriver driver = new ChromeDriver();

ClassNotFoundException using Selenium Standalone Server

I have a grails/groovy project that has one feature that uses selenium standalone server to do some test automation.
I keep getting this error running my grails project in production mode. If I run it directly from IntelliJ it works perfectly so I'm not sure what exactly is wrong.
Here is the relevant code:
WebDriver driver
DesiredCapabilities capability = DesiredCapabilities.chrome()
capability.setBrowserName("chrome")
capability.setPlatform(Platform.WINDOWS)
driver = new RemoteWebDriver( new URL("http://192.168.83.124:4444/wd/hub"), capability);
I'm getting a ClassNotFoundException error on the last line.
In my libraries for the project I'm using selenium-java-2.53.0.jar, selenium-server-standalone-2.53.0.jar and sources has selenium-java-2.53.0-srcs.jar
I have absolutely no idea what's wrong and I've searched the internet exhaustively to find a solution but have found nothing. Any help is appreciated.
Here is the full text of the error:
2017-12-08 15:59:56,381 [http-bio-8080-exec-1] ERROR
errors.GrailsExceptionResolver - ClassNotFoundException occurred when processing request: [GET] /Diversotron-0.1/api/edit
com.google.common.base.Function. Stacktrace follows:
java.lang.ClassNotFoundException: com.google.common.base.Function
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2585)
at java.lang.Class.getDeclaredConstructors(Class.java:1906)
at
org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:46)
at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:33)
at diversotron.PropotronService.setPropotron(PropotronService.groovy:25)
at diversotron.ApiController.edit(ApiController.groovy:53)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
It's because Selenium isn't declared in my BuildConfig.groovy file. That's why it ran via IntelliJ but not in production. Doing a grails prod war will not include the libraries. They have to be specified in the buildconfoig.groovy file.
I had to add these lines.
def seleniumVersion = "2.53.0"
and in dependencies I had to add this:
runtime "org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion"
Hopefully this will help someone else down the line!
Map chrome Options = new Map();
ChromeOptions.put("binary","/use/lib/chromium-browser/chromium-browser");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
Web Driver driver = new Chrome Driver(capabilities);
try this

Exception by using SafariDriver

I'm trying to run selenium safari driver.
My code is: driver = new SafariDriver();
But I get the following exception:
Caused by: java.lang.NoClassDefFoundError: org/jboss/netty/channel/ChannelFactory
at org.openqa.selenium.safari.SafariDriverCommandExecutor.<init>(SafariDriverCommandExecutor.java:76)
at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:58)
at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:42)
at com.ca.automation.utils.WebDriverFactory.initWebDriver(WebDriverFactory.java:168)
at com.ca.automation.utils.WebDriverFactory.getWebDriver(WebDriverFactory.java:210)
at com.ca.automation.utils.BaseSelenium.<init>(BaseSelenium.java:43)
at com.ca.automation.pb.strategicPlanning.CrudDriversBTest.<init>(CrudDriversBTest.java:20)
There could be a solution: Selenium 2 WebDriver NoClassDefFoundErrorS. You just need to use the standalone version or add all the jars to the build path.

Geb Exception: java.lang.NoClassDefFoundError: geb/error/GebException

IDE is Configured to use:
java: 7
geb: 0.9.1
Selenium java client and web driver: 2.35
When running the simple groovy script:
import geb.Browser
def browser = new Browser()
I get the following error:
Caught: java.lang.NoClassDefFoundError: geb/error/GebException
java.lang.NoClassDefFoundError: geb/error/GebException
at dave.run(dave.groovy:12)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.ClassNotFoundException: geb.error.GebException
... 2 more
Everything compiles just fine and according to every document available, I should be okay.
Any ideas?
Case Closed!
According to http://mvnrepository.com/artifact/org.gebish/geb-core/0.9.1, namely the "This artifact depends on ..." section, I needed some more dependencies.

illegalAccessError while using chromedriver with selenium

I am getting IllegalAccessError while using chromedriver in selenium. I have added chromedriver.exe to my path, and also set it in java code. here is my code
System.setProperty("webdriver.chrome.driver","C:/Users/me/Documents/chromedriver/chromedriver.exe");
WebDriver driver = new ChromeDriver();
here is the console output:
Exception in thread "main" java.lang.IllegalAccessError: tried to access method org.openqa.selenium.remote.service.DriverService.checkExecutable(Ljava/io/File;)V from class org.openqa.selenium.chrome.ChromeDriverService
at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:39)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.usingDriverExecutable(ChromeDriverService.java:104)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:72)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:107)
I have also tried running the chromedriver.exe and then executing the code, still getting the error.
This is probably caused by using an older version of selenium, where the checkExecutable method was still private