This question already has answers here:
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
(9 answers)
Selenium-TestNG-Maven - Getting "java.lang.NoClassDefFoundError: org/openqa/selenium/firefox/FirefoxDriver"
(2 answers)
Closed 2 years ago.
I have this script in InteliJ Idea
package com.test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class Main {
public static void main(String[] args) throws InterruptedException {
// write your code here
WebDriver driver = new ChromeDriver();
driver.get("https://cs.wikipedia.org/wiki/Wiki");
WebElement link;
link = driver.findElement(By.linkText("English"));
link.click();
Thread.sleep(5000);
WebElement searchbox;
searchbox = driver.findElement(By.id("searchInput"));
searchbox.sendKeys("Software");
Thread.sleep(5000);
driver.quit();
}
}
When i tried to run it it gives me this error:
"C:\Program Files\Java\jdk-10.0.2\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.1.1\lib\idea_rt.jar=51622:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.1.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Users\Jenda\IdeaProjects\test\out\production\test;D:\automatizace testů\selenium\selenium-java-3.141.59\client-combined-3.141.59.jar;D:\automatizace testů\selenium\selenium-java-3.141.59\libs\byte-buddy-1.8.15.jar;D:\automatizace testů\selenium\selenium-java-3.141.59\libs\commons-exec-1.3.jar;D:\automatizace testů\selenium\selenium-java-3.141.59\libs\guava-25.0-jre.jar;D:\automatizace testů\selenium\selenium-java-3.141.59\libs\okhttp-3.11.0.jar;D:\automatizace testů\selenium\selenium-java-3.141.59\libs\okio-1.14.0.jar;D:\automatizace testů\selenium\selenium-java.jar;D:\automatizace testů\selenium\guava-14.0.jar;D:\automatizace testů\selenium\json-20080701.jar;D:\automatizace testů\selenium\selenium-api-2.31.0.jar" com.test.Main
Error: Unable to initialize main class com.test.Main
Caused by: java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
Process finished with exit code 1
could you please give me some advice what is wrong?
Related
New to SO & test automation & selenium. I got introduced to gitpod while attempting https://www.lambdatest.com/certifications/.
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 please point out what I'm doing wrong here?
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.
Below line of code is incorrect:
WebDriver driver = WebDriverManager.chromedriver().create();
Try the below code:
public static void main(String[] args) throws InterruptedException {
// below line is used to setup chromedriver using WDM
WebDriverManager.chromedriver().setup();
//initialize the driver object
WebDriver driver = new ChromeDriver();
// Navigate to the demoqa website
driver.get("https://www.lambdatest.com/selenium-playground/checkbox-demo");
Thread.sleep(3000);
driver.quit();
}
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 4 years ago.
I am getting Java Null Pointer Exception when trying to run the below code. The test gets failed before the Web page even loads completely.
I have increased the page load timeout and Implicit wait time, but still that didn't work. The same web page is getting loaded within 4 seconds when directly launched through browser. Please find the below code:
//Loginpagetest.java
Loginpage loginpage = new Loginpage();
public LoginPageTest() throws IOException {
super();
}
#BeforeMethod
public void setup(){
initialize();
}
#Test(priority=1)
public void loginPageTitleTest(){
String actualTitle = loginpage.validateLoginPageTitle();
String expectedTitle = "#1 Free CRM software in the cloud for sales and service";
Assert.assertEquals(actualTitle,expectedTitle);
}
//TestBase.java
public void initialize(){
String browsername = prop.getProperty("browser");
if(browsername.equals("chrome")){
System.setProperty("webdriver.chrome.driver","C:\\Users\\Pranaykumar\\Downloads\\"chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver(options);
}else if(browsername.equals("mozilla")){
System.setProperty("webdriver.gecko.driver","E:\\geckodriver.exe");
driver = new FirefoxDriver();
}
driver.manage().window().maximize();
//driver.manage().deleteAllCookies();
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.get(prop.getProperty("url"));
}
//Loginpage.java
public String validateLoginPageTitle(){
return driver.getTitle();
}
//Console
[RemoteTestNG] detected TestNG version 6.14.3
Starting ChromeDriver 2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387) on port 42802
Only local connections are allowed.
[1548934220.587][WARNING]: Timed out connecting to Chrome, retrying...
Jan 31, 2019 5:00:25 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
FAILED: loginPageTitleTest
java.lang.NullPointerException
at com.crm.qa.pages.Loginpage.validateLoginPageTitle(Loginpage.java:37)
at com.crm.qa.testcases.LoginPageTest.loginPageTitleTest(LoginPageTest.java:30)
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)
The likely scenario is that you are creating a new instance of the driver inside your Loginpage page object instead of passing the existing instance so it's not initialized... thus the NPE.
Looks like this is not timeout issue, It’s showing NullPointerException. Maybe driver is null.
Check your chrome driver path is correct or not.
‘FAILED: loginPageTitleTest
java.lang.NullPointerException
at com.crm.qa.pages.Loginpage.validateLoginPageTitle(Loginpage.java:37)’
If it’s timeout issue, you should get TimeoutExcepton.
Can you please try to wait explicitly for an specific object in initialize() function and after the driver.get(prop.getProperty("url")) line as below code :
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(objectShouldPresent)));
Kindly remove double quotes(") before chromedriver_win32
System.setProperty("webdriver.chrome.driver","C:\\Users\\Pranaykumar\\Downloads\\"chromedriver_win32\\chromedriver.exe");
I little help here will be appreciated.I am simply trying to open a site using selenium and here is the code. Getting java.lang.IllegalStateException error.
package pkg1;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
//import org.openqa.selenium.firefox.FirefoxDriver;
public class training1 {
/**
* #param args
*/
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
System.setProperty("webdriver.chrome.driver","D:\\SeleniumTools\\chromedriver\\chromedriver.exe");
System.out.println("Welcome to Selenium");
driver.get("https://in.yahoo.com/");
}
}
----- Error -----
Exception in thread "main" 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: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.<init>(ChromeDriver.java:124)
at pkg1.training1.main(training1.java:14)
You must set path of the chromedriver.exe before calling new ChromeDriver()
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","D:\\SeleniumTools\\chromedriver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
System.out.println("Welcome to Selenium");
driver.get("https://in.yahoo.com/");
}
I exported a script from selenium IDE 1.9.0 as Java/TestNG/RemoteControl.
I would like to run this script using TestNG within Eclipse and I want to see the script play back in Firefox browser.
I did some search online, but I could not make it work. I need some instructions and guidance on how to make the code work. Your help is greatly appreciated.
Here is my code:
import java.util.List;
import org.testng.annotations.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import static org.testng.Assert.*;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
public class search_donor_suzy_ng //extends SeleneseTestNgHelper {
#BeforeTest
public void setUp() throws Exception {
//initizlize Firefoxbrowser:
WebDriver ffoxdriver = new FirefoxDriver();
String baseUrl = "www.google.com"; //sample URL
}
#Test
public void testSearch_donor_suzy_ng() throws Exception {
// set overall speed of the test case
selenium.setSpeed("4000");
selenium.open("/?html=openid");
selenium.click("css=input[type=\"submit\"]");
selenium.waitForPageToLoad("30000");
Thread.sleep(4000);
selenium.type("id=edit-name", "jeffshu");
selenium.type("id=edit-pass", "tEgvz9xsaNjnwe4Y");
selenium.click("id=edit-submit");
selenium.waitForPageToLoad("30000");
Thread.sleep(4000);
selenium.click("id=cmp_admin");
selenium.waitForPageToLoad("30000");
selenium.click("id=quicksearch_anchor");
selenium.click("css=img[alt=\"Member\"]");
selenium.waitForPageToLoad("30000");
selenium.type("id=search_name", "suzy");
selenium.click("css=input[type=\"image\"]");
selenium.click("link=Balagia, Suzy");
selenium.waitForPageToLoad("30000");
}
#AfterTest
public void tearDown() throws Exception {
ffoxdriver.quit();
}
}
For starters, you do need to refer to the documentation # http://docs.seleniumhq.org/docs/03_webdriver.jsp
In your code, you are intializing the driver object in your beforetest method, which you are not using. Driver is Webdriver's way of launching your browser, whereas in your testmethod you are using selenium and selenium 1 commands. As a quick step, you can replace your selenium with driver (put your declaration of driver in class scope and method scope). SeleneseTestngHelper is also selenium1.
Make sure you have the necessary webdriver jars in your project.
Certain commands in webdriver are different than selenium 1 and you might see compile erros when you do the replacement. Look at the methods available with driver. and use corresponding commands eg. Use get() of webdriver instead of open(). You can refer the javadocs for this or use your ide to get to know these.
I was trying to read through the mails in my gmail account using java mail API. This is the code:
import java.util.*;
import java.io.*;
import java.awt.*;
import javax.mail.*;
import javax.mail.search.FlagTerm;
import javax.mail.Flags.Flag;
public class MailPharser {
/**
* #param args
*/
public void mailRead()
{
Folder inbox;
// TODO Auto-generated method stub
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imaps");
try
{
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("imaps");
store.connect("imap.gmail.com","<mailid#gmail.com>", "<password>");
inbox = store.getFolder("Inbox");
System.out.println("No of Unread Messages : " + inbox.getUnreadMessageCount());
}
catch (Exception ex)
{ System.out.println("Error caught"); ex.printStackTrace(); }
}
public static void main(String[] args) {
MailPharser mp = new MailPharser();
mp.mailRead();
}
}
While running, i am getting the below error:
javax.mail.MessagingException: Connection reset;
nested exception is:
java.net.SocketException: Connection reset
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:670)
at javax.mail.Service.connect(Service.java:295)
at javax.mail.Service.connect(Service.java:176)
at MailPharser.mailRead(MailPharser.java:26)
at MailPharser.main(MailPharser.java:40)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at com.sun.net.ssl.internal.ssl.InputRecord.readFully(Unknown Source)
at com.sun.net.ssl.internal.ssl.InputRecord.read(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:548)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:352)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:233)
at com.sun.mail.iap.Protocol.<init>(Protocol.java:113)
at com.sun.mail.imap.protocol.IMAPProtocol.<init>(IMAPProtocol.java:111)
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:637)
... 4 more
I added trace and see that the connect call is failing. Am i doing anything wrong? any help would do. thanks in advance...
It's probably a network problem unrelated to JavaMail, e.g., a proxy or firewall between you and Gmail.
If you want to find out whether it's your code that's broken or the network that's broken, you can test using the code that comes with JavaMail. If the JavaMail code works, then you know there's something wrong with your code, and you can use the JavaMail code in the FAQ to improve your code.
If you discover that it's a network problem, the JavaMail FAQ also has tips for debugging it further.