-4

I have written this code to sign in the GMail, but it does not work.

It proceed till email id only then it displays the following error:

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"Passwd"}
Command duration or timeout: 17 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 02:56:46'
System info: host: 'ACE-PC', ip: '192.168.15.108', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_51'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=42.0, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 22f95743-5d66-4ac1-810c-aeb7a64fe5a8
*** Element info: {Using=id, value=Passwd}
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:348)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:389)
    at org.openqa.selenium.By$ById.findElement(By.java:215)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:340)
    at loginpkg.Logcls.main(Logcls.java:51)
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"Passwd"}
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 02:56:46'
System info: host: 'ACE-PC', ip: '192.168.15.108', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_51'
Driver info: driver.version: unknown
    at <anonymous class>.FirefoxDriver.prototype.findElementInternal_(file:///C:/Users/ADMINI~1/AppData/Local/Temp/anonymous3066282820874264242webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:10667)
    at <anonymous class>.FirefoxDriver.prototype.findElement(file:///C:/Users/ADMINI~1/AppData/Local/Temp/anonymous3066282820874264242webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:10676)
    at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///C:/Users/ADMINI~1/AppData/Local/Temp/anonymous3066282820874264242webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12643)
    at <anonymous class>.DelayedCommand.prototype.executeInternal_(file:///C:/Users/ADMINI~1/AppData/Local/Temp/anonymous3066282820874264242webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12648)
    at <anonymous class>.DelayedCommand.prototype.execute/<(file:///C:/Users/ADMINI~1/AppData/Local/Temp/anonymous3066282820874264242webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12590)

Is it possible to fix this?

Tagir Valeev
  • 97,161
  • 19
  • 222
  • 334
sapana
  • 37
  • 1
  • 10
  • if you want to read email from gmail then why are you using selenium for that you can do it with Java API too . i can share code with you – fahad Oct 30 '15 at 04:17
  • The answer is Yes, it is possible to fix but you haven't posted any code at all that we can look at and make suggestions on how to fix. Please read the guide [How do I ask a good question](http://stackoverflow.com/help/how-to-ask), especially the part on Minimal, Complete, and Verifiable example (MCVE). This will help you solve problems for yourself. If you do this and are still stuck you can come back and post your MCVE, what you tried, and what the results were so we can better help you. – JeffC Nov 08 '15 at 03:15

1 Answers1

2

You should use an explicit wait. Have a look at the docs here.

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(
           ExpectedConditions.visibilityOfElementLocated(By.id("Passwd")));
driver.findElement(By.id("Passwd")).sendKeys("xyz");

For a better explanation, do have a look at this answer of mine - Gmail login fail using Selenium webdriver. Showing element not found for password

Community
  • 1
  • 1
JRodDynamite
  • 12,325
  • 5
  • 43
  • 63