illegalAccessError while using chromedriver with selenium - 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

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 in thread "main" java.lang.IllegalStateException even when path of driver is set

I am getting below exception when I am running a selenium browser initialization using java main method. The driver is available at the right path.
The path to the driver executable must be set by the
webdriver.chrome.driver system property; for more information, see
https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest
version can be downloaded from
http://chromedriver.storage.googleapis.com/index.html at
com.google.common.base.Preconditions.checkState(Preconditions.java:738)
at
org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)
at
org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32)
at
org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
at
org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:330)
at
org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
at
org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:124)
at
invokebrowser.myfirsttestcase.initBroiwser(myfirsttestcase.java:23)
at invokebrowser.myfirsttestcase.main(myfirsttestcase.java:16)
Code Snippet
System.setProperty("Webdriver.chrome.driver","C:\\Javalibs\\chromedriver.exe");
WebDriver driver = new ChromeDriver();//getting exception here
In the code, Webdriver.code.driver..., W is mentioned in capital letter. It has to be in small letter as shown in the error message.
System.setProperty("webdriver.chrome.driver","C:\\Javalibs\\chromedriver.exe");
Hope this helps you. Thanks.
Here is the Answer to your Question:
While you work with Selenium 3.4.0, chromedriver 2.29 & Chrome 58.x you have to specify the absolute path of the chromedriver through System.setProperty
It's worth mentioning that the System Property is webdriver.chrome.driver
While you mention the absolute path of the chromedriver through System.setProperty, you have to either provide front slashes "/" or escape the back slashes "\\"
Your own code block will work for you with this simple twist:
System.setProperty("webdriver.chrome.driver","C:\\Javalibs\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
OR
System.setProperty("webdriver.chrome.driver","C:/Javalibs/chromedriver.exe");
WebDriver driver = new ChromeDriver();
Let me know if this Answers your Question.

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.

NullPointer Exception In running testCases via Selenium webDriver in Chrome

I am trying to run my test cases on Chrome and I had copied the path in the Properties file,but still console is throwing annoying statements like:
ERROR: The path to the chromedriver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://code.google.com/p/chromium/downloads/list
FAILED CONFIGURATION: #BeforeTest startWebSession
java.lang.NullPointerException
One thing I have found is that the Chrome driver cannot be started from within Eclipse. It must be run from a command prompt. At least on Windows 7 64-bit.
Trying to run it from within Eclipse produces this exception:
Exception in thread "main" java.lang.IllegalStateException: The webdriver.chrome.driver system property defined chromedriver executable does not exist: C:\Windows\System32\chromedriver.exe
This problem only occurs for Chrome. IE and FireFox work fine from within Eclipse.
Download the chrome driver from http://code.google.com/p/chromedriver/downloads/list
Initialize your driver object in the following manner -
System.setProperty("webdriver.chrome.driver","C:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
By doing this the chrome driver works properly.
This is how do I initialize the ChromeDriver:
public RegulationUI() throws Exception{
ChromeDriverService service = ChromeDriverService.createDefaultService();
File file = new File(RegulationUI.class.getResource("/chromedriver.exe").toURI());
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, file.getAbsolutePath());
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
driver = new ChromeDriver(service,options);
}
BTW my test class is named RegulationUI
Try this, it works for me and moreover, I know that this is "multicomputer" solution - our project is in subversion and this way everybody can run it, even if we have differently setup where exactly on disk the "working folder" for IDE is
Please download chromedriver.exe for Google chrome browser
please download IEdriver.exe for Internet explore.
Please And kept these files in a root folder of windows for simplicity. Lets consider your operating systems installed on c:\ (C Driver) create a folder name Selenium on C-Drive and Kept these binary(.exe) files. like c:\selenium
in your Testcase/testScript Write as
//For Chrome Browser:
Webdriver driver = new ChromeDriver();
java.io.File file = new File("c:\\selenium\\chromedriver.exe");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
If you are using maven then try to use following in your pom:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>RELEASE</version>
</dependency>
and use it like this for chrome in your setup:
ChromeDriverManager.getInstance().setup();
driver = new ChromeDriver();