I've been keep on getting NoSuchElementException whenever I try to get an web element. I know that the web element becomes present after some time. So, I've explicitly waited for 5-10 seconds until the web element gets loaded but even then I am still getting NoSuchElementException. Does anyone know how to prevent this exception? Here is my code:

String s=System.getProperty("user.dir");
System.setProperty("webdriver.chrome.driver", s+"\\Chrome090615\\chromedriver.exe");
ChromeDriver driver=new ChromeDriver();

    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    else {
        new WebDriverWait(driver, 5).until(ExpectedConditions.visibilityOfElementLocated(By.id("ebFrm")));
        System.out.println("Waiting for 5 secs");
    boolean ispresent=driver.findElementByXPath("//*[@id='sendSMS']/a").isDisplayed();
    System.out.println("Clicked sendSms");

I'm getting exception for the 'sendSMS' id. Whenever it tries to find this element, it throws NoSuchElementException all the time!


1 Answer 1


First of all, wait for the element you'll be clicking. Right now you're waiting for a different element.

Here's how: https://stackoverflow.com/questions/20903231/selenium-wait-until-element-is-present

Then, if you still get that error, the ID is probably wrong and thus not actually present on the page (in the same frame).

And why do you use XPath to locate by ID? Using findElementById is much cleaner.

  • Thanks @FDM for reply. trying your suggestion now and will update here thereafter!!
    – lss mesy
    Jun 15, 2015 at 6:27
  • It didn't work out :-( though it gets explicitly wait for the specified time. I've tried all locators(i.e, id, csspath, xpath) but it fails to find that element. I don't know why this is happening all the time :-(
    – lss mesy
    Jun 15, 2015 at 7:05
  • Do you have an URL on which we can test?
    – FDM
    Jun 15, 2015 at 7:39
  • Can you please share the html snippet
    – QAMember
    Jun 15, 2015 at 8:25
  • 2
    Never mind guys..I found that i need to switch its iframe whereas this element is located. but anyway thanks for your replies !
    – lss mesy
    Jun 15, 2015 at 8:49

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.