In Selenium maven project not able to lunch the chrome browser [duplicate] - selenium

This question already has answers here:
Mac OSX - IllegalStateException: The driver is not executable:
(12 answers)
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property
(4 answers)
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property with Selenium GeckoDriver
(1 answer)
Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist while running Selenium Test on Ubuntu
(1 answer)
java.lang.IllegalStateException: The driver executable does not exist: while trying to execute tests through Selenium, ChromeDriver and Chrome
(4 answers)
Closed 2 years ago.
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 version 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.(ChromeDriver.java:123)
at iotdatanormalization.Datanormalization.beforeClass(Datanormalization.java:27)
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)

enter code here
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>2.2.5</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>2.50.0</version>//Your chrome driver version
</dependency>
package example;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
import io.github.bonigarcia.wdm.WebDriverManager;
public class DepChrome {
#Test
public void testBrowser() {
WebDriver driver;
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
driver.get("https://google.com");
String title = driver.getTitle();
System.out.println(title);
driver.quit();
}
}

Pls check your chrome driver path ,error is saying there is no chrome driver at your path
#Test
public void testLogin() throws InterruptedException {
System.setProperty("webdriver.chrome.driver","chromepath);
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get(url);

Related

java.lang.NoClassDefFoundError Error while using WebDriverManager in Java project

I have created a plain Java Project and added all selenium 4.0.1/testng 7 and WebDriverManager 5.0.3 jars and set up classpath.
My Code here is
WebDriverManager.chromedriver().setup();
WebDriver driver= new ChromeDriver();
There is no compilation error, however, when execute as TestNG Class getting below error
java.lang.NoClassDefFoundError: org/apache/hc/core5/http/ClassicHttpRequest
at SeleniumSampleTest.checkTest(SeleniumSampleTest.java:15)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:598)
at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:173)
at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:824)
at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.testng.TestRunner.privateRun(TestRunner.java:794)
at org.testng.TestRunner.run(TestRunner.java:596)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:377)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:371)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:332)
at org.testng.SuiteRunner.run(SuiteRunner.java:276)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1212)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1134)
at org.testng.TestNG.runSuites(TestNG.java:1063)
at org.testng.TestNG.run(TestNG.java:1031)
at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109)
Caused by: java.lang.ClassNotFoundException: org.apache.hc.core5.http.ClassicHttpRequest
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 28 more
When I use the same code but build the project as a maven, then not getting any issues.
Any lights on this error will help to move ahead in the Java project
Please refer complete code here
[https://gist.github.com/veenadevi/62e7098c9809b2f0d2a1baa68141c028][1]
try this way->
public String baseURL=readconfig.getApplicationURL();
public static WebDriver driver;
public static Logger logger;
#Parameters("browser")
#BeforeClass
public void setup(String br)
{
//log
logger=Logger.getLogger("UnifyJobsV1");
PropertyConfigurator.configure("Log4j.properties");
if(br.equals("chrome"))
{
System.setProperty("webdriver.chrome.driver",readconfig.getChromePath());
driver=new ChromeDriver();
}
else if(br.equals("firefox"))
{
System.setProperty("webdriver.gecko.driver",readconfig.getFirefoxPath());
driver=new FirefoxDriver();
}
driver.get(baseURL);
}
#AfterClass
public void tearDown() {
driver.quit();
}
There is com.intellij.rt.testng.IDEARemoteTestNG.run in stacktrace, so you're using Intellij IDEA. Since maven execution works, there is no dependencies conflicts.
It looks like IDE related issue.
I can suggest 2 options.
1 Try to mvn clean, and Build -> Rebuild Project in IDE.
2 Also restarting IDEA and File -> Invalidate caches could help.
Hope something will help you.
I faced the same problem when I moved the project from mac to windows.
Adding the Jars (httpclient and httcore) solved the problem for me.
I refered it from the github solution issue-359

InvalidArgumentException: invalid argument: Unsupported locator strategy: -custom error with Appium using Selenium ChromeDriver and Chrome

I'm trying to run the test.ai plugin for appium (https://github.com/testdotai/appium-classifier-plugin). It has a custom locator strategy. I set up appium (version 1.13.0, also tried downgrading to 1.9.2-beta.2) and did:
'npm install -g test-ai-classifier'
it was installed, as shown:
https://i.stack.imgur.com/fwtkt.png
I then wrote a simple test to check if everything is set up correctly:
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.MobileBy;
import io.appium.java_client.MobileElement;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import org.junit.Before;
import org.junit.After;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
public class TestClass {
private AppiumDriver driver;
private By cart = MobileBy.custom("cart");
#Before
public void setUp() throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "9");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "NB1GAD17B1504154");
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");
HashMap<String, String> customFindModules = new HashMap<>();
customFindModules.put("ai", "test-ai-classifier");
capabilities.setCapability("customFindModules", customFindModules);
capabilities.setCapability("shouldUseCompactResponses", false);
driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), capabilities);
}
#After
public void tearDown(){
}
#Test
public void testMethod(){
goToWebsite(driver);
openCartUseAi(driver);
}
public void goToWebsite(AppiumDriver driver){
driver.get("https://www.ebay.com/");
}
public void openCartUseAi(AppiumDriver driver){
driver.findElement(cart).click();
}
}
This causes the following error when ran:
/usr/lib/jvm/java-1.11.0-openjdk-amd64/bin/java -ea -Didea.test.cyclic.buffer.size=1048576 -javaagent:/home/piotrek/intellij/ideaIC-2019.1.2/idea-IC-191.7141.44/lib/idea_rt.jar=46303:/home/piotrek/intellij/ideaIC-2019.1.2/idea-IC-191.7141.44/bin -Dfile.encoding=UTF-8 -classpath /home/piotrek/intellij/ideaIC-2019.1.2/idea-IC-191.7141.44/lib/idea_rt.jar:/home/piotrek/intellij/ideaIC-2019.1.2/idea-IC-191.7141.44/plugins/junit/lib/junit-rt.jar:/home/piotrek/intellij/ideaIC-2019.1.2/idea-IC-191.7141.44/plugins/junit/lib/junit5-rt.jar:/home/piotrek/IdeaProjects/appiumTestMVN/target/test-classes:/home/piotrek/Downloads/selenium-server-standalone-3.141.59.jar:/home/piotrek/.m2/repository/io/appium/java-client/7.0.0/java-client-7.0.0.jar:/home/piotrek/.m2/repository/org/seleniumhq/selenium/selenium-java/3.141.59/selenium-java-3.141.59.jar:/home/piotrek/.m2/repository/org/seleniumhq/selenium/selenium-chrome-driver/3.141.59/selenium-chrome-driver-3.141.59.jar:/home/piotrek/.m2/repository/org/seleniumhq/selenium/selenium-edge-driver/3.141.59/selenium-edge-driver-3.141.59.jar:/home/piotrek/.m2/repository/org/seleniumhq/selenium/selenium-firefox-driver/3.141.59/selenium-firefox-driver-3.141.59.jar:/home/piotrek/.m2/repository/org/seleniumhq/selenium/selenium-ie-driver/3.141.59/selenium-ie-driver-3.141.59.jar:/home/piotrek/.m2/repository/org/seleniumhq/selenium/selenium-opera-driver/3.141.59/selenium-opera-driver-3.141.59.jar:/home/piotrek/.m2/repository/org/seleniumhq/selenium/selenium-remote-driver/3.141.59/selenium-remote-driver-3.141.59.jar:/home/piotrek/.m2/repository/org/seleniumhq/selenium/selenium-safari-driver/3.141.59/selenium-safari-driver-3.141.59.jar:/home/piotrek/.m2/repository/net/bytebuddy/byte-buddy/1.8.15/byte-buddy-1.8.15.jar:/home/piotrek/.m2/repository/org/apache/commons/commons-exec/1.3/commons-exec-1.3.jar:/home/piotrek/.m2/repository/com/google/guava/guava/25.0-jre/guava-25.0-jre.jar:/home/piotrek/.m2/repository/com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.jar:/home/piotrek/.m2/repository/org/checkerframework/checker-compat-qual/2.0.0/checker-compat-qual-2.0.0.jar:/home/piotrek/.m2/repository/com/google/errorprone/error_prone_annotations/2.1.3/error_prone_annotations-2.1.3.jar:/home/piotrek/.m2/repository/com/google/j2objc/j2objc-annotations/1.1/j2objc-annotations-1.1.jar:/home/piotrek/.m2/repository/org/codehaus/mojo/animal-sniffer-annotations/1.14/animal-sniffer-annotations-1.14.jar:/home/piotrek/.m2/repository/com/squareup/okhttp3/okhttp/3.11.0/okhttp-3.11.0.jar:/home/piotrek/.m2/repository/com/squareup/okio/okio/1.14.0/okio-1.14.0.jar:/home/piotrek/.m2/repository/org/seleniumhq/selenium/selenium-support/3.141.59/selenium-support-3.141.59.jar:/home/piotrek/.m2/repository/org/seleniumhq/selenium/selenium-api/3.141.59/selenium-api-3.141.59.jar:/home/piotrek/.m2/repository/com/google/code/gson/gson/2.8.5/gson-2.8.5.jar:/home/piotrek/.m2/repository/org/apache/httpcomponents/httpclient/4.5.6/httpclient-4.5.6.jar:/home/piotrek/.m2/repository/org/apache/httpcomponents/httpcore/4.4.10/httpcore-4.4.10.jar:/home/piotrek/.m2/repository/commons-logging/commons-logging/1.2/commons-logging-1.2.jar:/home/piotrek/.m2/repository/commons-codec/commons-codec/1.10/commons-codec-1.10.jar:/home/piotrek/.m2/repository/cglib/cglib/3.2.8/cglib-3.2.8.jar:/home/piotrek/.m2/repository/org/ow2/asm/asm/6.2.1/asm-6.2.1.jar:/home/piotrek/.m2/repository/org/apache/ant/ant/1.10.3/ant-1.10.3.jar:/home/piotrek/.m2/repository/org/apache/ant/ant-launcher/1.10.3/ant-launcher-1.10.3.jar:/home/piotrek/.m2/repository/commons-validator/commons-validator/1.6/commons-validator-1.6.jar:/home/piotrek/.m2/repository/commons-beanutils/commons-beanutils/1.9.2/commons-beanutils-1.9.2.jar:/home/piotrek/.m2/repository/commons-digester/commons-digester/1.8.1/commons-digester-1.8.1.jar:/home/piotrek/.m2/repository/commons-collections/commons-collections/3.2.2/commons-collections-3.2.2.jar:/home/piotrek/.m2/repository/org/apache/commons/commons-lang3/3.8/commons-lang3-3.8.jar:/home/piotrek/.m2/repository/commons-io/commons-io/2.6/commons-io-2.6.jar:/home/piotrek/.m2/repository/org/springframework/spring-context/5.1.0.RELEASE/spring-context-5.1.0.RELEASE.jar:/home/piotrek/.m2/repository/org/springframework/spring-aop/5.1.0.RELEASE/spring-aop-5.1.0.RELEASE.jar:/home/piotrek/.m2/repository/org/springframework/spring-beans/5.1.0.RELEASE/spring-beans-5.1.0.RELEASE.jar:/home/piotrek/.m2/repository/org/springframework/spring-core/5.1.0.RELEASE/spring-core-5.1.0.RELEASE.jar:/home/piotrek/.m2/repository/org/springframework/spring-jcl/5.1.0.RELEASE/spring-jcl-5.1.0.RELEASE.jar:/home/piotrek/.m2/repository/org/springframework/spring-expression/5.1.0.RELEASE/spring-expression-5.1.0.RELEASE.jar:/home/piotrek/.m2/repository/org/aspectj/aspectjweaver/1.9.1/aspectjweaver-1.9.1.jar:/home/piotrek/.m2/repository/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar:/home/piotrek/.m2/repository/junit/junit/4.12/junit-4.12.jar:/home/piotrek/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit4 TestClass,testMethod
Jun 07, 2019 1:43:44 PM io.appium.java_client.remote.AppiumCommandExecutor$1 lambda$0
INFO: Detected dialect: W3C
org.openqa.selenium.InvalidArgumentException: invalid argument: Unsupported locator strategy: -custom
(Session info: chrome=74.0.3729.157)
(Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729#{#29}),platform=Linux 5.0.0-15-generic x86_64)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'piotrek-VirtualBox', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '5.0.0-15-generic', java.version: '11.0.3'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {browserName: Chrome, customFindModules: {ai: test-ai-classifier}, databaseEnabled: false, desired: {browserName: Chrome, customFindModules: {ai: test-ai-classifier}, deviceName: NB1GAD17B1504154, platformName: android, platformVersion: 9, shouldUseCompactResponses: false}, deviceManufacturer: HMD Global, deviceModel: TA-1004, deviceName: NB1GAD17B1504154, deviceScreenSize: 1440x2560, deviceUDID: NB1GAD17B1504154, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, platform: LINUX, platformName: Android, platformVersion: 9, shouldUseCompactResponses: false, takesScreenshot: true, warnings: {}, webStorageEnabled: false}
Session ID: 6cb83c3b-3405-483a-8dc3-21eec62b4676
*** Element info: {Using=-custom, value=ai:cart}
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:323)
at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:62)
at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
at io.appium.java_client.FindsByCustom.findElementByCustom(FindsByCustom.java:38)
at TestClass.openCartUseAi(TestClass.java:64)
at TestClass.testMethod(TestClass.java:49)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Process finished with exit code 255
Can anyone tell me what I'm doing wrong? When rewriting this test to not use the plugin, everything works fine, so Appium is set up correctly.
I had a look at this doc, but still can't see what I'm missing: http://appium.io/docs/en/advanced-concepts/element-finding-plugins/
Thank You in advance for your help!
PS not sure if this is relevant, but I'm using an Ubuntu virtual machine for this
This error message...
org.openqa.selenium.InvalidArgumentException: invalid argument: Unsupported locator strategy: -custom
...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session due to an invalid argument within an Unsupported locator strategy.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
You are using chromedriver=2.46
Release Notes of chromedriver=2.46 clearly mentions the following :
Supports Chrome v71-73
You are using chrome=74.0
Release Notes of ChromeDriver v74.0 clearly mentions the following :
Supports Chrome v74
So there is a clear mismatch between ChromeDriver v2.46 and the Chrome Browser v74.0
Solution
Upgrade ChromeDriver to ChromeDriver v75.0 level.
Upgrade Chrome to Chrome v75 level. (as per ChromeDriver v75.0 release notes)
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
Okay, got this figured out myself. Apparently Appium and Test.Ai don't yet support a custom locator strategy on web apps. This only works on native apps for now. Shame they didn't put this info in their documentation :P
Set this capability,
setCapability("chromeOptions", ImmutableMap.of("w3c", false));
On my side got the same issue, I was try out this code it worked smoothly.

Unable to open Google chrome using selenium webdriver [duplicate]

This question already has answers here:
WebDriverException: unknown error: cannot find Chrome binary error with Selenium in Python for older versions of Google Chrome
(8 answers)
Closed 3 years ago.
I am trying open a google chrome using selenium webdriver but I'm getting the below error :
Starting ChromeDriver 2.38.552522 (437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb) on port 18885
Only local connections are allowed.
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: cannot find Chrome binary
(Driver info: chromedriver=2.38.552522 (437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb),platform=Windows NT 6.1.7600 x86) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 110 milliseconds
Build info: version: '3.141.5', revision: 'd54ebd709a', time: '2018-11-06T11:58:41'
System info: host: 'ADMIN-PC', ip: '192.168.244.1', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_191'
Driver info: driver.version: ChromeDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$errorHandler$0(JsonWireProtocolResponse.java:54)
at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:125)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
at demo.main(demo.java:9)
I have tried everything but no use.
Below is my program :
public class demo {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\\Users\\Admin\\Desktop\\Internal job application\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://google.com");
}
}
Need assistance on what action needs to taken
You are getting that error because your chrome browser is not installed in the default installation directory or selenium not able to find executable chrome browser file.
To solve this problem, you need to tell the program where your chrome browser executable is present and for that you can use ChromeOptions class like below :
public class demo {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\\Users\\Admin\\Desktop\\Internal job application\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.setBinary("/path/to/chrome/binary"); // Provide absolute executable chrome browser path with name and extension here
WebDriver driver = new ChromeDriver(options);
driver.get("http://google.com");
}
}
I hope it helps...
Install Chrome browser in destination by default.
In this line:
System.setProperty("webdriver.chrome.driver", "destination to file"
destination to file is not destination to installed Chrome browser, but destination to downloaded here chrome driver.

org.openqa.selenium.SessionNotCreatedException: Unable to find a matching set of capabilities while initiating Firefox v37 through Selenium v3.11.0

I am trying to run test a run a website in Firefox, but I am getting error "The path to the driver executable must be set by the webdriver.gecko.driver system property;" I have set the path correctly, still don't know where the problem is. Here is my code:
if (browsers.equalsIgnoreCase("Firefox"))
{
String driverPath = System.getProperty("user.dir") + "\\src/test/java\\drivers\\geckodriver.exe";
System.setProperty("webdriver.firefox.marionette", "false");
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
} else if (browsers.equalsIgnoreCase("Chrome")) {
// String driverPath = System.getProperty("user.dir") +
// "\\src\\Drivers\\chromedriver";
// System.setProperty("webdriver.chrome.driver", driverPath);
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
Here is the Failure Trace of my code:
FAILED CONFIGURATION: #BeforeClass launchBrowser
org.openqa.selenium.SessionNotCreatedException: Unable to find a matching set of capabilities
Build info: version: '3.8.0', revision: '924c4067df', time: '2017-11-30T11:36:59.109Z'
System info: host: 'DSCHD-PC-180', ip: '192.168.6.122', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_161'
Driver info: driver.version: FirefoxDriver
remote stacktrace:
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$new$0(W3CHandshakeResponse.java:57)
at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$getResponseFunction$2(W3CHandshakeResponse.java:104)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:142)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:120)
at Utility.UtilityMethods.openBrowser(UtilityMethods.java:26)
at TestCases.LoginTestCase.launchBrowser(LoginTestCase.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:59)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:455)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:222)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:168)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:105)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
SKIPPED CONFIGURATION: #AfterClass quitBrowser
SKIPPED: registration
To keep things simple, as you are using Selenium Client v3.11.0 and Firefox v37 you need to download the latest GeckoDriver from mozilla/geckodriver and save it any where within your system. Next within the System.setProperty() line pass the Key webdriver.gecko.driver along with the Value as the absolute path of the GeckoDriver and finally through DesiredCapabilities class set the capability marionatte to false and merge into an instance of FirefoxOptions instance to initiate the Firefox browser as follows :
System.setProperty("webdriver.gecko.driver", "C:/path/to/geckodriver.exe");
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability("marionatte", false);
FirefoxOptions opt = new FirefoxOptions();
opt.merge(dc);
FirefoxDriver driver = new FirefoxDriver(opt);
driver.get("https://stackoverflow.com");
System.out.println("Application opened");
System.out.println("Page Title is : "+driver.getTitle());
driver.quit();
Update
As per your comment update you are using GeckoDriver v0.20.1.
But if you look back at the Release Notes of GeckoDriver v0.18.0 it clearly mentions :
geckodriver now recommends Firefox 53 and greater
So using GeckoDriver v0.18.0 and above you have to mandatory use Firefox 53 and greater. To get rid of this constraint you can downgrade either to any of these versions :
GeckoDriver v0.17.0
GeckoDriver v0.16.1
This is how system property is set:
System.setProperty("webdriver.gecko.driver", "C:\\...\\geckodriver.exe");
I had this error for 2 days, the solution for me was in Set.Platform, put Platform.ANY or Platform.Windows because Platform.WIN10 not worked, marionette wasn't necessary.
public class Main { public static RemoteWebDriver driver;
public static void main(String[] args) throws MalformedURLException {
System.setProperty("webdriver.gecko.driver", "D:/Lib/geckodriver.exe");
DesiredCapabilities desiredCapabilities = new
DesiredCapabilities().firefox();
desiredCapabilities.setPlatform(Platform.ANY);
desiredCapabilities.setBrowserName("firefox");
driver = new RemoteWebDriver(new URL("http://172.20.19.182:5557/wd/hub"),
desiredCapabilities);
driver.navigate().to("http://www.google.com");
driver.findElementByName("q").sendKeys("execute automation");
driver.findElementByName("q").sendKeys(Keys.ENTER);
driver.close();
// write your code here
}
you are using user.dir that basically means : current working directory
Here is the code that let you initialize firefox browser using selenium.
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:\\your\\gecko\\driver\\path\\geckodriver.exe");
driver = new firefoxDriver();
That's it ! you can use Firefox driver to performs several operations like :
1. driver.get(String args0);
2. driver.getCurrentUrl();
3. driver.getPageSource();
4. driver.getTitle();
5. driver.findElememt(By args0);
6. driver.findElements(By args0);
7. driver.naviagate();
8. driver.manage();
9. driver.close();
10. driver.quit();
11. driver.switchTo();
12. driver.getWindowHandle();
13. driver.getWindowHandles();
Please let me know if you have any concerns related to this.
Just updated your code. You will have to set driver path while setProperty and user webdriver.gecko.driver for latest firefox driver.
if (browsers.equalsIgnoreCase("Firefox")) {
String driverPath = System.getProperty("user.dir") + "\\src\\test\\java\\drivers\\geckodriver.exe";
System.setProperty("webdriver.firefox.driver", "driverPath");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("marionette", false);
FirefoxOptions options = new FirefoxOptions();
options.merge(capabilities);
FirefoxDriver driver = new FirefoxDriver(options);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
else if (browsers.equalsIgnoreCase("Chrome")) {
// String driverPath = System.getProperty("user.dir") +
// "\\src\\Drivers\\chromedriver";
// System.setProperty("webdriver.chrome.driver", driverPath);
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
Let me know.

Getting the error java.lang.NoSuchMethodError error while launching the headless browser

While launching the headless browser using Phantomjs, getting the below exception
java.lang.NoSuchMethodError: org.openqa.selenium.os.CommandLine.find(Ljava/lang/String;)Ljava/lang/String;
at org.openqa.selenium.phantomjs.PhantomJSDriverService.findPhantomJS(PhantomJSDriverService.java:232)
at org.openqa.selenium.phantomjs.PhantomJSDriverService.createDefaultService(PhantomJSDriverService.java:181)
at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:104)
at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:94)
OS is Mac
Config for launching headless browser is
File src = new File("src/test/resources/phantomjs_mac");
System.setProperty("phantomjs.binary.path", src.getAbsolutePath());
driver = new PhantomJSDriver();
Updated the complete trace
FAILED CONFIGURATION: #BeforeMethod LaunchBrowser
java.lang.NoSuchMethodError: org.openqa.selenium.os.CommandLine.find(Ljava/lang/String;)Ljava/lang/String;
at org.openqa.selenium.phantomjs.PhantomJSDriverService.findPhantomJS(PhantomJSDriverService.java:232)
at org.openqa.selenium.phantomjs.PhantomJSDriverService.createDefaultService(PhantomJSDriverService.java:181)
at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:104)
at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:94)
at baseHelper.BrowserLauncher.LaunchBrowser(BrowserLauncher.java:108)
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:497)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:514)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:215)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:589)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:782)
at org.testng.TestRunner.run(TestRunner.java:632)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:113)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:206)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:177)
Here is the Answer to your Question:
When we use Phantomjs we have to provide the absolute path of the Phantomjs executable. Remember to specify the WebDriver Class before specifying the Implementation new PhantomJSDriver();
Here is the example in Windows:
File path=new File("C:\\Utility\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe");
System.setProperty("phantomjs.binary.path",path.getAbsolutePath());
WebDriver driver= new PhantomJSDriver();
driver.manage().window().maximize();
driver.navigate().to("https://www.google.co.in/");
PS: Kindly convert it into Mac recognizable format.
Let me know if this Answers your Question.
System.setProperty("phantomjs.binary.path", src.getAbsolutePath()) does not work in case of PhanotmJS
However, you can setup the DesiredCapabilities and pass it to the PhantomJSDriver.
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, System.getProperty("user.dir") + /drivers/phantomjs.exe");
WebDriver driver = new PhantomJSDriver(capabilities);
driver.navigate().to("https://www.google.co.in/");
driver.get("http://google.com");
Make sure your pom file does not use selenium version 3.6.0. Instead, use below dependency.
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.5.3</version>
</dependency>
Also, WebDriver driver = new PhantomJSDriver(); will always result in an error so you cannot use an empty constructor.
I hope that helps.