package captionlabs;
import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Login_captionlabs {
    public static void main(String[] args) {
         System.setProperty("webdriver.gecko.driver", "D:\\selenium\\geckodriver.exe");
        FirefoxDriver driver = new FirefoxDriver();
  • Trying with other locators like id, name – user24314 May 24 '17 at 7:58

When you are calling findElement the element probably doesn't exist yet on your page.

You need to wait explicitly for the element to become visible, here's how: https://stackoverflow.com/questions/20903231/how-to-wait-until-an-element-is-present-in-selenium


You are getting the "NoSuchElementException" because as soon as you enter the url you are using sendkeys even before the web page has completely loaded.

I would suggest After you open the url wait till the webelement that you are looking for to get loaded first and then use sendkeys

so the refactored code should look somewhat like this.


//Initializing the 'wait' with a 30 seconds deplay before it throws a NoSuchElementException
WebDriverWait wait = new WebDriverWait(driver,30);



Let me know if this helps you or not.

  • Code could be much cleaner by assigning the Wait return value to a variable instead of using the XPath twice. – FDM May 24 '17 at 13:00
  • I agree but I wanted to keep it simple for the user. Thanks – Alok May 24 '17 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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