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();
            driver.findElement(By.xpath(".//*[@id='login-form']/fieldset/section[1]/label[2]/input")).sendKeys("[email protected]");
  • Trying with other locators like id, name
    – user24314
    Commented May 24, 2017 at 7:58

2 Answers 2


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);


driver.findElement(By.xpath(".//*[@id='login-form']/fieldset/section[1]/label[2]/input")).sendKeys("[email protected]");

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
    Commented May 24, 2017 at 13:00
  • I agree but I wanted to keep it simple for the user. Thanks
    – Alok
    Commented May 24, 2017 at 13:45

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.