I am trying to do Bus Search first on Travelyaari.com and then Modify the Bus Search, The Modify Search button seems to be clicked, however, previous Bus search result page is getting loaded and my case is failing with error as

'Unable to locate element' org.openqa.selenium.NoSuchElementException.

I have tried using xpath for identifying the 'Modify Search' button, the .isDisplayed() is true however when doing .click(), getting 'Unable to locate element' org.openqa.selenium.NoSuchElementException.

Please help me to resolve this?

  • Welcome to StackExchange. whenever asking a question on this forum it is advisable to put your actual code snippet so that people can review it and answer accordingly. Also go through this link on How to ask a good question
    – Alok
    Commented Jan 7, 2018 at 19:47
  • Add your HTML Code to locate the button element. Also edit your question with what have you tried, which Locator/XPath is used to locate the button element?
    – Bharat Mane
    Commented Jan 9, 2018 at 10:52

2 Answers 2


There could be 2 possibilities for your NoSuchElementException

  1. That locator you are using to find the webelement is wrong. Hence it is giving you the error.

  2. You are trying to click on the webelement even before it is loaded completed on the page. To solve this. Always use the explicit wait to let the webelement get loaded before performing any execution on it. A very common method used for the wait is as follows.

    /* Initialize the WebDriverWait, with 30 seconds of wait time. */   
    WebDriverWait wait = new WebDriverWait(driver, 30);

Add this code(make changes for locator) before the line where you are getting the error.


If you are using this assertion Modify Search.isDisplayed() and it is returning true. Also as per your observations The Modify Search button seems to be clicked. So it might be throwing error on next step after click.

You can apply wait before the action and wait for the particular element after action is performed, like after clicking 'Modify Search' button you can wait for 'Modify Search' Popup to appear. In most of the software testing company while testing a product this approach is preferred.

Also you can put the code in If Else loop to find out the way. You can try the below code snippet.

if ('ModifySearch_Button'.isDisplayed()){


WebDriverWait wait = new WebDriverWait(driver, 60);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("Modify Search Popup")));

  • Why button was clicked but not redirecting to next page and not pop up any exception? Any solution?
    – learnerA
    Commented Sep 26, 2019 at 2:22

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.