Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5956717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:17:49+00:00 2026-05-22T18:17:49+00:00

I am using Selenium+JUnit+Eclipse I have 3 classes in 3 packages. Test class as

  • 0

I am using Selenium+JUnit+Eclipse
I have 3 classes in 3 packages. Test class as A(in default Package), Activity class as B(In activity package), Repository class as C(in objectRepository package).

If i do all activities in class A then its working fine. But if I separate the activities in class B and calling classB methods in classA then its throwing java.lang.NullPointerException error…

Code for ClassA.java

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
import junit.framework.TestCase;
import org.junit.Test;
import activityPkg.ClassB;


public class ClassA extends TestCase {
ClassB objB = new ClassB();
public void setUp() throws Exception
{
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "https://www.google.com");
selenium.start();
selenium.windowFocus();
selenium.windowMaximize();}

@Test
public void testA() throws Exception
{
selenium.open("/");
try
{
Thread.sleep(5000);
String result = objB.MethodB();
}
catch(Exception e)
{
e.printStackTrace();
}
}

Code for ClassB.java

package activityPkg;
import com.thoughtworks.selenium.Selenium;

public class RegressionTools {
Selenium selenium;
ObjectRepository objRep = new ObjectRepository();
public String MethodB() throws Exception
{
String value=null;
try
{
selenium.start();
if(selenium.isElementPresent("//input[@name='btnG' and @value='Google Search']"))
{
System.out.println("Element is present");
value = pass;
}
else
{
System.out.println("Element is not present");
value = Fail;
}

}
catch(Exception e)
{
e.printStackTrace();
}
return value;
}
}

But everytime its stopping from IF condition of MethodB and coming to catch block.
Why it’s not even entering into IF or ELSE condition.
Did I miss anything there?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:17:50+00:00Added an answer on May 22, 2026 at 6:17 pm

    you don’t have any selenium instance in your class B. I guess the exception you have is NullPointerException

    You start your selenium instance in your first class, and got no reference pointing to it in your class B

    Good practice is to have a SeleniumFixture utility which holds a reference to the started instance and manage the lifecycle of the selenium server during the test suite

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Selenium RC and created all scripts in java (Using Junit test case)
I have recorded a very simple test case Using the Selenium IDE integrated with
I'm trying to run Selenium RC 1.0.3 using Java 6, JUnit 4, and Eclipse
We are using Junit + Selenium to webtest our webpage. But we have run
I am writing some UI tests using Selenium and i have a JavaScript Tree
We are using JUnit - Selenium for our web tests. We use Maven to
I am using Selenium RC with Junit framework. I am trying to upload a
I am using Selenium for web application testing. After having finished all the testing,
I have been using Selenium a lot lately (testing an ExtJs app) and while
I'm using Selenium Java 2.0b3 . I have this code: ... WebDriver driver =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.