0
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.get("https://my.development.sourcefile.com");
            driver.findElement(By.xpath(".//*[@id='login-form']/fieldset/section[1]/label[2]/input")).sendKeys("info@captionlabs.com");
  • Trying with other locators like id, name – user24314 May 24 '17 at 7:58
1

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

|improve this answer|||||
1

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.

driver.get("https://my.development.sourcefile.com");

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

wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//*[@id='login-form']/fieldset/section[1]/label[2]/input"));

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

Let me know if this helps you or not.

|improve this answer|||||
  • 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.