nullpointer exception

0 votes
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class Testscript01 {

static WebDriver d;

public static void setup() {

System.setProperty("webdriver.chrome.driver", "C:\\Users\\Shaikshavali Shaik\\chromedriver.exe");

// System.setProperty("webdriver.gecko.driver", "C:\\Users\\Shaikshavali

// Shaik\\Downloads\\geckodriver-v0.26.0-win64\\geckodriver.exe");

WebDriver d = new ChromeDriver();

d.manage().timeouts().implicitlyWait(Util.WAIT_TIME, TimeUnit.SECONDS);

d.get(Util.BASE_URL);

}

public static void main(String[] args) throws Exception {

// TODO Auto-generated method stub

setup();

d.findElement(By.xpath("//input[@name='uid']")).clear();

d.findElement(By.xpath("//input[@name='uid']")).sendKeys(Util.USER_NAME);

d.findElement(By.cssSelector("input[name='password']")).clear();

d.findElement(By.cssSelector("input[name='password']")).sendKeys(Util.PASSWRD);

d.findElement(By.name("btnLogin")).click();

String ACTUAL_TILLE = d.getTitle();

if(ACTUAL_TILLE.contains(Util.EXPCTED_TITLE))

{

System.out.println("Test Case : Passed");

}

else

{

System.out.println("Test Case : Failed");

}

}

}
Apr 30, 2020 in Selenium by Syed
• 120 points
1,665 views
Hey @Syed, could you please post the error log that you get when executing this code snippet. It would help comprehend the query. Also, give some additional info on the objective of your code.
Thanks for responding.

this was the error while executing.

Exception in thread "main" java.lang.NullPointerException

at Testscript01.main(Testscript01.java:26)
Have you added the Selenium Standalone JAR to your Java Project in Eclipse?
yes, everything is done. I guess the error is regarding java method and handling, and i have very little knowledge about java
Are you using TestNG framework?

Hi, @Syed,

Regarding your query Name of the public class must match the name of .java file, in which it is placed. So either

  • rename your file from Main.java to Testscript01.java
  • rename the class from public class Testscript01  to public class Main {
If you don't have a public class main there is no Main.java. Don't confuse the main class with a main method. Your main method is in Testscript.01.java.

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Page Factory: StaleElementReference Exception

Usually, a StaleElementReferenceException is thrown when: 1. ...READ MORE

answered Apr 21, 2018 in Selenium by king_kenny
• 3,710 points
1,429 views
0 votes
1 answer

Selenium Exception: Element is not visible

Finding the element before locating the one ...READ MORE

answered May 7, 2018 in Selenium by king_kenny
• 3,710 points
7,221 views
0 votes
1 answer

NoSuchElementException exception with headless chrome and selenium

As you are seeing NoSuchElementException you can consider using ...READ MORE

answered May 7, 2018 in Selenium by Samarpit
• 5,910 points
8,246 views
+1 vote
1 answer

Throwing Hamcrest exception message while actual and expected are same

Below will help you: Its due to string ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,910 points
778 views
0 votes
4 answers
0 votes
1 answer

When does ElementNotInteractable exception occurs?

This Selenium exception is thrown when an ...READ MORE

answered May 17, 2019 in Selenium by Frankie
• 9,830 points
644 views
0 votes
1 answer

How exception handling can be done in Selenium?

@Suresh, Selenium exceptions can be handled in ...READ MORE

answered May 23, 2019 in Selenium by Suman
685 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