ChromeDriver Selenium exception - selenium

Im using Mac laptop, I got this from youtube for mac tutorial, but its working for other students
Forgive me I am new to selenium
Not sure if Im missing something
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Main {
public static void main(String [] args) {
System.setProperty("webdriver.chrome.driver","/Users/c054148/Downloads/chromedriver");
WebDriver obj = new ChromeDriver();
obj.get("https://www.google.com");
}
} Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap
at org.openqa.selenium.remote.service.DriverService$Builder.(DriverService.java:259)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.(ChromeDriverService.java:101)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:94)
at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:123)
at Main.main(Main.java:8)
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.ImmutableMap
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 5 more

Seems you have missed the extension of the ChromeDriver. It should be chromedriver.exe
System.setProperty("webdriver.chrome.driver","/Users/c054148/Downloads/chromedriver.exe");

Related

Running Selenium-java automation inside Gitpod

New to the platform & test automation & selenium. I got introduced to Gitpod while attempting https://www.lambdatest.com/certifications/.
for starters I'm stuck trying to run the below simple code snippet in side Gitpod
package project.maven.selenium;
import org.openqa.selenium.WebDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
public class WebDriverManagerDemo {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = WebDriverManager.chromedriver().create();
// Navigate to the demoqa website
driver.get("https://www.lambdatest.com/selenium-playground/checkbox-demo");
Thread.sleep(3000);
driver.quit();
}
}
Couldn't find a way pass the error below,
Exception in thread "main" io.github.bonigarcia.wdm.config.WebDriverManagerException: There was an error creating WebDriver object for Chrome
at io.github.bonigarcia.wdm.WebDriverManager.instantiateDriver(WebDriverManager.java:1775)
at io.github.bonigarcia.wdm.WebDriverManager.create(WebDriverManager.java:425)
at project.maven.selenium.WebDriverManagerDemo.main(WebDriverManagerDemo.java:9)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
can someone point out what I'm doing wrong please?
Researched hours but Selenium on Gitpod is not much of a topic, read the getting started guide with Gitpod too, to find a resolution to my problem but no luck before posting here.

Exception in thread Unresolved compilation problems:

This is my script:
package sampleTests;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class AdminLogin {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver(); //Launches Firefox Browser with blank url
driver.close();
}
}
When I run the script, am getting below error, I tried to add the java lib in Class path instead of Module path, still the issue not resolved, someone please help;
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
WebDriver cannot be resolved to a type FirefoxDriver cannot be resolved to a type at sampleTests.AdminLogin.main(AdminLogin.java:10)
You have to set the path of the Geckodriver (the executable that is used for Firefox tests using Selenium).
Search for Geckodriver in Google.
Download the executable as per your system (Win/Mac/Linux)
Set the path of the executable in your tests as given below -
package sampleTests;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class AdminLogin {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.gecko.driver",Path_of_Firefox_Driver");
// example for Windows
System.setProperty("webdriver.gecko.driver",D:\\GeckoDriver\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://testautomationu.applitools.com/");
driver.quit();
}
}

Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: C:\Sujata_Selenium_workspace\chromedriver.exe [duplicate]

This question already has an answer here:
java.lang.IllegalStateException: The driver executable does not exist: C:\Users\jagrelot\workspace\AntBuildExample\chromedriver.exe with ChromeDriver
(1 answer)
Closed 3 years ago.
xception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: C:\Sujata_Selenium_workspace\chromedriver.exe
Errors is showing.
package seleniumWebdriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class LaunchBrowser {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Sujata_Selenium_workspace\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://www.seleniumhq.org/download/");
}
}
I think your chromedriver does not placed in the path your defined "C:\Sujata_Selenium_workspace\chromedriver.exe"
Either place the chromedriver in the path or place it somewhere in D or E drive like
D:/Selenium/chromedriver.exe
Code like
System.setProperty("webdriver.chrome.driver", "D:/Selenium/chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://www.seleniumhq.org/download/");

Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: C:\Selenium\geckodriver.exe

I am getting below exception while trying to open a site
Exception in thread "main" java.lang.IllegalStateException: The driver
executable does not exist: C:\Selenium\geckodriver.exe at
com.google.common.base.Preconditions.checkState(Preconditions.java:534)
at
org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:136)
at
org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:131)
at
org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:41)
at
org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:141)
at
org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:339)
at
org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:158)
at
org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:120)
at
org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:98)
at com.tst.Test.main(Test.java:12)
My code is:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Test {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver","C:/Selenium/geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.get("http://www.google.co.in");
I am using selenium 3 with geckodriver-v0.19.1-win64.zip. and java version is 1.8.
Please help me out
You need to setPath properly for binary file. On windows, I prefer \\ instead od /, Can you please try this?-
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver","C:\\Selenium\\geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.get("http://www.google.co.in");

Selenium Server not starting

package com.memoir.client.widgets.memogen;
import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.thoughtworks.selenium.DefaultSelenium;
#SuppressWarnings("deprecation")
public class TestHomepage extends SeleneseTestCase {
#Override
#Before
public void setUp() throws Exception {
//selenium = new DefaultSelenium("localhost", 4444, "*firefox", "https://64.79.128.233/staging/");
selenium = new DefaultSelenium("localhost", 4444, "*firefox /usr/bin/firefox", "https://64.79.128.233/staging/");
selenium.start();
}
#Test
public void testTesting4() throws Exception {
selenium.setSpeed("2000");
selenium.windowMaximize();
//selenium.open("/memosyn/");
selenium.open("/staging/");
selenium.waitForPageToLoad("60000");
//Checking for page layout in the beginning of the web page
assertEquals("1", selenium.getElementIndex("//*[#id='isc_G']"));
assertEquals("Please contact support#systems.com for questions or comments.", selenium.getText("id=contactText"));
//assertEquals("MemoWeb V3.3.5963M", selenium.getText("//*[#id='isc_WidgetCanvas_1_widget']/div/table/tbody/tr/td[2]"));
assertEquals("14", selenium.getElementHeight("scLocator=//VLayout[ID=\"loginBox\"]/"));
assertEquals("447", selenium.getElementWidth("scLocator=//VLayout[ID=\"loginBox\"]/"));
assertEquals("35", selenium.getElementHeight("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=email]/title"));
assertEquals("207", selenium.getElementWidth("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=email]/title"));
assertEquals("35", selenium.getElementHeight("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=password]/title"));
assertEquals("207", selenium.getElementWidth("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=password]/title"));
assertEquals("35", selenium.getElementHeight("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=rememberMe]/textbox"));
assertEquals("203", selenium.getElementWidth("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=rememberMe]/textbox"));
assertEquals("22", selenium.getElementHeight("scLocator=//Button[ID=\"submitButton\"]/"));
assertEquals("100", selenium.getElementWidth("scLocator=//Button[ID=\"submitButton\"]/"));
assertEquals("MemoWeb", selenium.getTitle());
assertEquals("Email :", selenium.getText("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=email||title=Email]/title"));
assertEquals("Password :", selenium.getText("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=password||title=Password]/title"));
assertEquals("Remember me on this computer", selenium.getText("scLocator=//DynamicForm[ID=\"loginItems\"]/item[name=rememberMe||title=Remember%20me%20on%20this%20computer]/textbox"));
}
#Override
#After
public void tearDown() throws Exception {
selenium.stop();
}
}
This is the code and when I run this by starting the selenium server i get this error.
What could be the reason for the error? Is it that my firefox profile is not set properly?
java.lang.RuntimeException: Could not start Selenium session: Failed to start new browser session: org.openqa.selenium.server.browserlaunchers.InvalidBrowserExecutableException: The specified path to the browser executable is invalid.
at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:109)
at com.memoir.client.widgets.memogen.TestHomepage.setUp(TestHomepage.java:16)
at junit.framework.TestCase.runBare(TestCase.java:132)
at com.thoughtworks.selenium.SeleneseTestCase.runBare(SeleneseTestCase.java:230)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: com.thoughtworks.selenium.SeleniumException: Failed to start new browser session: org.openqa.selenium.server.browserlaunchers.InvalidBrowserExecutableException: The specified path to the browser executable is invalid.
at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:112)
at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:106)
at com.thoughtworks.selenium.HttpCommandProcessor.getString(HttpCommandProcessor.java:275)
at com.thoughtworks.selenium.HttpCommandProcessor.start(HttpCommandProcessor.java:237)
at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:100)
... 16 more
Can anyone help me fix this?
I get those errors and I have no clue please help me .
Selenium RC works on Eclipse with versions less that 12 . Can you pls check which version you are using