I have a strange behavior : I created Test Class with 2 Test Methods as below.

When I call AddLimitedBuyOrderwithRandom in the first method it works fine without any exception, but if I call AddLimitedBuyOrderwithRandom from the second method I get a NoSuchElement exception.

This is the code for the test class:

public class TestLoginPage extends TestBase {
    public HomePage homeobject;
    public NewOrdersLoginPage OrderLoginObject;
    public OrderMgmtPage OrdersMgmentObject;

    public void SuccessLogin() throws InterruptedException
        homeobject = new HomePage(driver);
        OrderLoginObject = new NewOrdersLoginPage(driver);
        OrderLoginObject.userLogin("140", "12345");
        OrdersMgmentObject = new OrderMgmtPage(driver);

    @Test(enabled= true)
    public void AddLimitOrderTest() throws InterruptedException
        OrdersMgmentObject = new OrderMgmtPage(driver);

and this is the code for AddLimitedBuyOrderwithRandom:

public void AddLimitedBuyOrderwithRandom(String SharesCount) throws InterruptedException
    selectDropdownByValue( companyList, "Company");
    typeText(ShareNoTxt, SharesCount);
    selectDropdownByValue(  OrderTypeList, "2");
    selectDropdownByValue( OrderValidityList, "0");
    double Pricerandom = getRandomNumberInRange(ReturnShareLimitDown(),ReturnShareLimitUp());

(Added from comments on answers) My base class is:

public class TestBase 
    public static WebDriver driver ; 
    public static String downloadPath = System.getProperty("user.dir") + "\\Downloads"; 
    public String BaseURL = "URL"; 

    public void startDriver(@Optional ("chrome") String browserType) 
        if (browserType.equalsIgnoreCase("chrome") ) 
            System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"/drivers/chromedriver.exe"); 
            driver = new ChromeDriver(); 
  • 1
    In your first test, you log on before going to the order management page. In the second test, you don't - is it possible that not being logged in is the problem?
    – Kate Paulk
    Commented Nov 13, 2018 at 13:37

2 Answers 2


Many things are hidden on the code. It can be anything on your code or on the application logic.

But most likely is that you have just performed login once. When you open the browser on the second test, Selenium cleans everything.

You would have to login again or save some cookie, using a @BeforeSuite method.

  • I Already use @BeforeSuit : how to save Cookies
    – Amr Shehab
    Commented Nov 14, 2018 at 9:36

Try to add wait before interacting with your element with waitForVisible.



Because on your first method, you have prior steps. Unlike in second step that you call it right away.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.