0

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?

Bharat Mane
6,78512 gold badges42 silver badges69 bronze badges
asked Jan 7, 2018 at 18:24
2
  • 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 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? Commented Jan 9, 2018 at 10:52

2 Answers 2

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);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("xpathValue")));
    

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

sameer joshi
5242 gold badges11 silver badges31 bronze badges
answered Jan 7, 2018 at 19:53
0

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()){
'ModifySearch_Button'.click(); 
WebDriverWait wait = new WebDriverWait(driver, 60);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("Modify Search Popup")));
}
Bharat Mane
6,78512 gold badges42 silver badges69 bronze badges
answered Jan 10, 2018 at 7:30
1
  • Why button was clicked but not redirecting to next page and not pop up any exception? Any solution? Commented Sep 26, 2019 at 2:22

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.