Unable to execute the exported jar file exported from eclipse for the selenium webdriver test

+1 vote

package devops;

//import org.openqa.selenium.By;

//import org.openqa.selenium.WebElement;

import org.openqa.selenium.htmlunit.HtmlUnitDriver;

public class htmlunitdriver {

public static void main(String[] args) {

HtmlUnitDriver driver = new HtmlUnitDriver(true);

driver.get("http://localhost/content/about-us.php");

//WebElement linkByText = driver.findElement(By.linkText("About Us"));

     

    // linkByText.click();

    if(driver.getPageSource().contains("ijaz"))

    

         System.out.println("Text is present in the page");

    

     else

     

         System.err.println("Text is not present in the page");

    driver.quit();

}

}

This code executes immaculately within eclipse. But when I tried to execute from the Linux terminal it throws errors. The error is as follows

Exception in thread "main" java.lang.reflect.InvocationTargetException
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
       at java.lang.reflect.Method.invoke(Method.java:498)
       at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:61)
Caused by: java.lang.IllegalStateException: 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 vers
ion can be downloaded from http://chromedriver.storage.googleapis.com/index.html
       at com.google.common.base.Preconditions.checkState(Preconditions.java:847)
       at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:134)
       at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:35)
       at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:159)
       at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:355)
       at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:94)
       at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
       at edureka.devops.main(devops.java:11)
       ... 5 more

 
Nov 13, 2019 in DevOps & Agile by Ijaz
• 130 points
1,387 views

1 answer to this question.

+2 votes
Hi Ijaz

Looks like when you are executing on the local machine, you have included the chrome driver. While executing it on the Linux terminal which does not have a GUI, the driver fails.

In this case, you will have to include the HTML driver instead of the chrome driver and package it the right way. It will run for sure . i have tried it on my project and it has worked.

Follow the steps mentioned in the link and you should be able to achieve it very easily

Regards,

RRR

PS: If this post solved your query or was useful in anyway, please upvote or mark it as answer.
answered Dec 4, 2019 by Raveendiran
• 980 points

Related Questions In DevOps & Agile

0 votes
1 answer
+5 votes
1 answer

How to program and get the Digital Ocean ID of the current Droplet from within the Droplet?

You can run curl http://169.254.169.254/metadata/v1/id within the ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by Atul
• 10,240 points
3,465 views
+3 votes
1 answer

Unable to find the TargetArguments path While configuring dot cover in VSTS

For your unable to find the TargetArguments ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by ajs3033
• 7,300 points
1,220 views
0 votes
1 answer

to check file has the same value or not i.e comparing file with stat module.

Try the following script: Do the second time ...READ MORE

answered May 1, 2018 in DevOps & Agile by shubham
• 7,340 points
4,171 views
0 votes
1 answer

Error: Unable to access elasticsearch in docker for windows

This is simple, just follow the below ...READ MORE

answered Sep 3, 2018 in DevOps & Agile by Sophie may
• 10,620 points
1,689 views
0 votes
1 answer
0 votes
2 answers

How to customize the RAM allocation on Docker for Windows?

Try this: docker update --cpu-shares 5120 -m 3000M ...READ MORE

answered Dec 7, 2018 in DevOps & Agile by Maverick
• 10,840 points
5,530 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP